From 3d34764022c5eac32125ac43fd87ef0d9600c191 Mon Sep 17 00:00:00 2001 From: Brad Gonzales Date: Wed, 4 Dec 2013 10:30:54 -0600 Subject: [PATCH] Issue #2566 Refactored BandwidthManagerCreators to load spring files using Executor.extractSpringFiles. Amend: Refactored Executor static modes specific methods into a EDEXModesUtil class in the edex.core.modes package. Move EdexMode, DefaultEdexMode, and EdexModesContainer to the same package. Change-Id: Ib6af9557ca8d875c5eff162b46bf56e2c041e0fb Former-commit-id: 72df38075f912ebe2049d955b8d10d93af8db44d [formerly 76a844ed3158bcc80dc0d4b751cad83d39fcbbc4] Former-commit-id: 410a00c72a76708dde938d30b9c1ef3819bea9cf --- edexOsgi/build.edex/esb/conf/modes.xml | 12 +- .../META-INF/MANIFEST.MF | 1 + .../uf/edex/core/modes}/DefaultEdexMode.java | 11 +- .../uf/edex/core/modes/EDEXModesUtil.java | 167 ++++++++++++++++++ .../uf/edex/core/modes}/EdexMode.java | 3 +- .../edex/core/modes}/EdexModesContainer.java | 3 +- .../MonolithicBandwidthManagerCreator.java | 13 +- .../ncf/NcfBandwidthManagerCreator.java | 13 +- .../bandwidth/BandwidthManager.java | 32 ++++ .../bandwidth/InMemoryBandwidthManager.java | 9 +- .../bandwidth/WfoBandwidthManagerCreator.java | 13 +- .../raytheon/uf/edex/esb/camel/Executor.java | 125 +------------ .../spring => core/modes}/EdexModeTest.java | 4 +- 13 files changed, 247 insertions(+), 159 deletions(-) rename edexOsgi/{com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring => com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes}/DefaultEdexMode.java (80%) create mode 100644 edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EDEXModesUtil.java rename edexOsgi/{com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring => com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes}/EdexMode.java (97%) rename edexOsgi/{com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring => com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes}/EdexModesContainer.java (94%) rename tests/unit/com/raytheon/uf/edex/{esb/camel/spring => core/modes}/EdexModeTest.java (96%) diff --git a/edexOsgi/build.edex/esb/conf/modes.xml b/edexOsgi/build.edex/esb/conf/modes.xml index 2b7adba772..bc501d81bc 100644 --- a/edexOsgi/build.edex/esb/conf/modes.xml +++ b/edexOsgi/build.edex/esb/conf/modes.xml @@ -236,7 +236,7 @@ ebxml.*\.xml dataDeliveryTemplate datadelivery-wfo-cron.xml - bandwidth-datadelivery-edex-impl-wfo.xml + bandwidth-datadelivery-.*-wfo.xml .*datadelivery.*-ncf.* .*datadelivery.*-monolithic.* harvester-* @@ -246,7 +246,7 @@ ebxml.*\.xml dataDeliveryTemplate - bandwidth-datadelivery-edex-impl-ncf.xml + bandwidth-datadelivery-.*-ncf.xml .*datadelivery.*-wfo.* .*datadelivery.*-monolithic.* @@ -298,7 +298,12 @@ grid-metadata.xml wxsrv-dataset-urn.xml - + + + bandwidth-datadelivery-inmemory-impl.xml + bandwidth-datadelivery.xml + bandwidth-datadelivery-wfo.xml + @@ -306,6 +311,7 @@ datadelivery-wfo-cron.xml dataDeliveryTemplate bandwidth-datadelivery-edex-impl-monolithic.xml + bandwidth-datadelivery-wfo.xml .*datadelivery.*-ncf.* diff --git a/edexOsgi/com.raytheon.uf.edex.core/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.core/META-INF/MANIFEST.MF index 1ac609843c..61c0e41f89 100644 --- a/edexOsgi/com.raytheon.uf.edex.core/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.core/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: com.raytheon.uf.edex.core, com.raytheon.uf.edex.core.dataplugin, com.raytheon.uf.edex.core.hdf5, + com.raytheon.uf.edex.core.modes, com.raytheon.uf.edex.core.props Require-Bundle: org.springframework;bundle-version="2.5.6", com.raytheon.uf.common.dataplugin;bundle-version="1.12.1174", diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/DefaultEdexMode.java b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/DefaultEdexMode.java similarity index 80% rename from edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/DefaultEdexMode.java rename to edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/DefaultEdexMode.java index c8673036d2..4b7974327e 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/DefaultEdexMode.java +++ b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/DefaultEdexMode.java @@ -17,15 +17,14 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.edex.esb.camel.spring; +package com.raytheon.uf.edex.core.modes; import java.io.File; import java.io.FilenameFilter; -import com.raytheon.uf.edex.esb.camel.Executor; - /** - * TODO Add Description + * An edex mode filter finds all spring XML files. For the case when no EDEX run + * configuration is specified. * *
  * 
@@ -33,6 +32,7 @@ import com.raytheon.uf.edex.esb.camel.Executor;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Apr 27, 2010            njensen     Initial creation
+ * Dec 05, 2013 2566       bgonzale    Migrated to edex.core.modes package.
  * 
  * 
* @@ -49,7 +49,8 @@ public class DefaultEdexMode implements FilenameFilter { */ @Override public boolean accept(File dir, String name) { - return name.contains("res/spring/") && name.endsWith(Executor.XML); + return name.contains(EDEXModesUtil.RES_SPRING) + && name.endsWith(EDEXModesUtil.XML); } } diff --git a/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EDEXModesUtil.java b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EDEXModesUtil.java new file mode 100644 index 0000000000..778feb1278 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EDEXModesUtil.java @@ -0,0 +1,167 @@ +/** + * 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.core.modes; + +import java.io.File; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.regex.Pattern; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import com.raytheon.uf.common.util.PropertiesUtil; +import com.raytheon.uf.edex.core.EDEXUtil; +import com.raytheon.uf.edex.core.props.PropertiesFactory; + +/** + * EDEX utility class for accessing mode and mode configuration files. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 5, 2013  2566       bgonzale     Initial creation.  Refactored from Executor.
+ * 
+ * 
+ * + * @author bgonzale + * @version 1.0 + */ + +public class EDEXModesUtil { + + public static final String XML = ".xml"; + + public static final Pattern XML_PATTERN = Pattern.compile("\\" + XML); + + public static final String RES_SPRING = "res/spring/"; + + public static final Pattern RES_SPRING_PATTERN = Pattern + .compile("res/spring/"); + + private static final String MODES_FILE = "modes.xml"; + + public static final String CONF_DIR = EDEXUtil.EDEX_HOME + File.separator + + "conf"; + + /** + * Populates files with a list of files that match in the specified + * directory + * + * Returns a list of plugins, etc + * + * @param jarDir + * @param files + * @return + * @throws IOException + * @throws JAXBException + */ + public static List extractSpringXmlFiles(List files, + String modeName) throws IOException, JAXBException { + FilenameFilter filter = getModeFilter(modeName); + String pluginDirStr = PropertiesFactory.getInstance() + .getEnvProperties().getEnvValue("PLUGINDIR"); + + List retVal = new ArrayList(); + File jarDirFile = new File(pluginDirStr); + File[] jars = jarDirFile.listFiles(); + + List jarList = new ArrayList(jars.length); + for (File p : jars) { + if (p.getName().endsWith(".jar")) { + JarFile jar = new JarFile(p); + jarList.add(jar); + } + } + + for (JarFile jar : jarList) { + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + JarEntry e = entries.nextElement(); + String name = e.getName(); + if (filter.accept(null, name)) { + files.add(name); + retVal.add(RES_SPRING_PATTERN.matcher( + XML_PATTERN.matcher(name).replaceAll("")) + .replaceAll("")); + } + } + + } + + return retVal; + } + + private static FilenameFilter getModeFilter(String modeName) throws IOException, + JAXBException { + File confDir = new File(CONF_DIR); + EdexModesContainer emc = getModesContainer(confDir); + EdexMode edexMode = emc.getMode(modeName); + + if (edexMode != null && edexMode.isTemplate()) { + throw new UnsupportedOperationException(modeName + + " is a template mode, and is not bootable."); + } + + FilenameFilter mode = edexMode; + + if (mode == null) { + if (modeName == null || modeName.length() == 0) { + mode = new DefaultEdexMode(); + } else { + throw new UnsupportedOperationException( + "No EDEX run configuration specified in modes.xml for " + + modeName); + } + } + return mode; + } + + private static EdexModesContainer getModesContainer(File confDir) + throws IOException, JAXBException { + File file = new File(confDir.getPath(), MODES_FILE); + + FileReader reader = null; + Unmarshaller msh = null; + try { + JAXBContext jaxbContext = JAXBContext + .newInstance(EdexModesContainer.class); + msh = jaxbContext.createUnmarshaller(); + reader = new FileReader(file); + EdexModesContainer emc = (EdexModesContainer) msh.unmarshal(reader); + return emc; + } finally { + if (reader != null) { + PropertiesUtil.close(reader); + } + } + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexMode.java b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexMode.java similarity index 97% rename from edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexMode.java rename to edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexMode.java index 0cda0096d3..9410f94d52 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexMode.java +++ b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexMode.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.edex.esb.camel.spring; +package com.raytheon.uf.edex.core.modes; import java.io.File; import java.util.ArrayList; @@ -44,6 +44,7 @@ import javax.xml.bind.annotation.XmlRootElement; * ------------ ---------- ----------- -------------------------- * Apr 22, 2010 njensen Initial creation * Sep 19, 2012 1195 djohnson Allow 0..n other modes to be included. + * Dec 05, 2013 2566 bgonzale Migrated to edex.core.modes package. * * * diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexModesContainer.java b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexModesContainer.java similarity index 94% rename from edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexModesContainer.java rename to edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexModesContainer.java index 765279255b..f5a8ba4dc2 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/spring/EdexModesContainer.java +++ b/edexOsgi/com.raytheon.uf.edex.core/src/com/raytheon/uf/edex/core/modes/EdexModesContainer.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.edex.esb.camel.spring; +package com.raytheon.uf.edex.core.modes; import java.util.ArrayList; @@ -37,6 +37,7 @@ import javax.xml.bind.annotation.XmlRootElement; * ------------ ---------- ----------- -------------------------- * Apr 22, 2010 njensen Initial creation * May 29, 2013 1989 njensen Removed high mem mode + * Dec 05, 2013 2566 bgonzale Migrated to edex.core.modes package. * * * diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/MonolithicBandwidthManagerCreator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/MonolithicBandwidthManagerCreator.java index 9f502bd81e..0a9f771c5b 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/MonolithicBandwidthManagerCreator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/MonolithicBandwidthManagerCreator.java @@ -24,7 +24,6 @@ import com.raytheon.uf.common.datadelivery.registry.Time; import com.raytheon.uf.common.datadelivery.registry.handlers.IDataSetMetaDataHandler; import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler; import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService; -import com.raytheon.uf.common.util.JarUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.BandwidthManager; import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager; @@ -49,6 +48,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Nov 13, 2013 2545 bgonzale Initial creation + * Dec 04, 2013 2566 bgonzale use bandwidthmanager method to retrieve spring files. * * * @@ -64,14 +64,9 @@ public class MonolithicBandwidthManagerCreator extends NcfBandwidthManager { - private static final String[] BANDWIDTH_MANAGER_FILES = new String[] { - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-monolithic-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-daos.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-eventbus.xml"), - JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo.xml") }; + public static final String MODE_NAME = "devRegistry"; + + private static final String[] BANDWIDTH_MANAGER_FILES = getSpringFileNamesForMode(MODE_NAME); /** * Constructor. diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/NcfBandwidthManagerCreator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/NcfBandwidthManagerCreator.java index 1c02d58de4..151229bcb3 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/NcfBandwidthManagerCreator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/ncf/NcfBandwidthManagerCreator.java @@ -34,7 +34,6 @@ import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandle import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService; import com.raytheon.uf.common.registry.event.UpdateRegistryEvent; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.util.JarUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.BandwidthManager; import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthManager; @@ -62,6 +61,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Nov 08, 2013 2506 bgonzale Added subscription notification service to bandwidth manager. * Nov 19, 2013 2545 bgonzale Added registryEventListener method for update events. * Reschedule updated shared subscriptions. + * Dec 04, 2013 2566 bgonzale use bandwidthmanager method to retrieve spring files. * * * @@ -75,14 +75,9 @@ public class NcfBandwidthManagerCreator impl */ static class NcfBandwidthManager extends EdexBandwidthManager { - private static final String[] NCF_BANDWIDTH_MANAGER_FILES = new String[] { - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-ncf-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-daos.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-eventbus.xml"), - JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-ncf.xml") }; + private static final String MODE_NAME = "centralRegistry"; + + private static final String[] NCF_BANDWIDTH_MANAGER_FILES = getSpringFileNamesForMode(MODE_NAME); /** * Constructor. diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java index b7857db4db..c10a085425 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.regex.Pattern; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -58,6 +59,7 @@ import com.raytheon.uf.common.util.algorithm.AlgorithmUtil.IBinarySearchResponse import com.raytheon.uf.edex.auth.req.AbstractPrivilegedRequestHandler; import com.raytheon.uf.edex.auth.resp.AuthorizationResponse; import com.raytheon.uf.edex.core.EDEXUtil; +import com.raytheon.uf.edex.core.modes.EDEXModesUtil; 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.BandwidthDataSetUpdate; @@ -126,6 +128,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * Nov 04, 2013 2506 bgonzale Added removeBandwidthSubscriptions method. * Nov 19, 2013 2545 bgonzale changed getBandwidthGraphData to protected. + * Dec 04, 2013 2566 bgonzale added method to retrieve and parse spring files for a mode. * * * @@ -139,6 +142,8 @@ public abstract class BandwidthManager protected static final IUFStatusHandler statusHandler = UFStatus .getHandler(BandwidthManager.class); + private static final Pattern RES_PATTERN = Pattern.compile("^res"); + // Requires package access so it can be accessed from the maintenance task final IBandwidthDao bandwidthDao; @@ -168,6 +173,33 @@ public abstract class BandwidthManager this.bandwidthDaoUtil = bandwidthDaoUtil; } + /** + * Get the list of mode configured spring file names for the named mode. + * + * @param modeName + * retrieve the spring files configured for this mode + * @return list of spring files configured for the given mode + */ + protected static String[] getSpringFileNamesForMode(String modeName) { + List fileList = new ArrayList(); + try { + EDEXModesUtil.extractSpringXmlFiles(fileList, modeName); + } catch (Exception e) { + throw new RuntimeException( + "Failed to determine spring files for mode " + modeName, e); + } + + String[] result = new String[fileList.size()]; + int i = 0; + for (String fileName : fileList) { + String name = RES_PATTERN.matcher(fileName).replaceFirst(""); + result[i++] = name; + statusHandler.debug("Spring file added: " + name + " for mode " + + modeName); + } + return result; + } + private List schedule(Subscription subscription, SortedSet cycles) { SortedSet retrievalTimes = bandwidthDaoUtil diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java index 8b38ca3e80..47945a7cec 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java @@ -29,7 +29,6 @@ import com.raytheon.uf.common.datadelivery.registry.Time; import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.common.util.JarUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; @@ -54,6 +53,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Jun 25, 2013 2106 djohnson init() now takes a {@link RetrievalManager} as well. * Jul 09, 2013 2106 djohnson Add shutdownInternal(). * Oct 2, 2013 1797 dhladky Generics + * Dec 04, 2013 2566 bgonzale use bandwidthmanager method to retrieve spring files. * * * @@ -65,13 +65,12 @@ class InMemoryBandwidthManager extends Bandw private static final IUFStatusHandler statusHandler = UFStatus .getHandler(InMemoryBandwidthManager.class); + private static final String MODE_NAME = "inMemoryBandwidthManager"; + // NOTE: NEVER add the bandwidth-datadelivery-eventbus.xml file to this // array, in-memory versions should not coordinate with the event bus in any // fashion - public static final String[] IN_MEMORY_BANDWIDTH_MANAGER_FILES = new String[] { - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-inmemory-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo.xml") }; + public static final String[] IN_MEMORY_BANDWIDTH_MANAGER_FILES = getSpringFileNamesForMode(MODE_NAME); /** * {@link BandwidthInitializer} which will make a copy of the current diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java index f7e0d79c00..65afbe1a37 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java @@ -37,7 +37,6 @@ import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandle import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService; import com.raytheon.uf.common.registry.event.UpdateRegistryEvent; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.util.JarUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; @@ -65,6 +64,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Added getBandwidthGraphData. * Reschedule updated local subscriptions. * Nov 27, 2013 2545 mpduff Get data by network + * Dec 04, 2013 2566 bgonzale use bandwidthmanager method to retrieve spring files. * * * @@ -80,14 +80,9 @@ public class WfoBandwidthManagerCreator static class WfoBandwidthManager extends EdexBandwidthManager { - private static final String[] WFO_BANDWIDTH_MANAGER_FILES = new String[] { - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-daos.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-eventbus.xml"), - JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo.xml") }; + private static final String MODE_NAME = "registry"; + + private static final String[] WFO_BANDWIDTH_MANAGER_FILES = getSpringFileNamesForMode(MODE_NAME); // TODO: Change to be DIed in Spring private final IBandwidthService ncfBandwidthService = new NcfBandwidthService(); diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java index cd26c0febf..7434b48ce8 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java +++ b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java @@ -21,34 +21,19 @@ package com.raytheon.uf.edex.esb.camel; import java.io.File; import java.io.FileFilter; -import java.io.FileReader; -import java.io.FilenameFilter; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.concurrent.CountDownLatch; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.regex.Pattern; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.raytheon.uf.common.util.PropertiesUtil; -import com.raytheon.uf.edex.core.EDEXUtil; -import com.raytheon.uf.edex.core.props.PropertiesFactory; +import com.raytheon.uf.edex.core.modes.EDEXModesUtil; import com.raytheon.uf.edex.esb.camel.context.ContextManager; -import com.raytheon.uf.edex.esb.camel.spring.DefaultEdexMode; -import com.raytheon.uf.edex.esb.camel.spring.EdexMode; -import com.raytheon.uf.edex.esb.camel.spring.EdexModesContainer; /** * Provides the central mechanism for starting the ESB @@ -68,6 +53,7 @@ import com.raytheon.uf.edex.esb.camel.spring.EdexModesContainer; * resources directory. * Feb 14, 2013 1638 mschenke Removing activemq reference in stop * Apr 22, 2013 #1932 djohnson Use countdown latch for a shutdown hook. + * Dec 04, 2013 2566 bgonzale refactored mode methods to a utility in edex.core. * * * @@ -77,15 +63,6 @@ import com.raytheon.uf.edex.esb.camel.spring.EdexModesContainer; public class Executor { - public static final String XML = ".xml"; - - private static final Pattern XML_PATTERN = Pattern.compile("\\" + XML); - - private static final Pattern RES_SPRING_PATTERN = Pattern - .compile("res/spring/"); - - private static final String MODES_FILE = "modes.xml"; - private static final CountDownLatch shutdownLatch = new CountDownLatch(1); public static void start() throws Exception { @@ -101,13 +78,10 @@ public class Executor { Thread.currentThread().setName("EDEXMain"); System.setProperty("System.status", "Starting"); - String pluginDirStr = PropertiesFactory.getInstance() - .getEnvProperties().getEnvValue("PLUGINDIR"); - List xmlFiles = new ArrayList(); List propertiesFiles = new ArrayList(); - File confDir = new File(EDEXUtil.EDEX_HOME + File.separator + "conf"); + File confDir = new File(EDEXModesUtil.CONF_DIR); File resourcesDir = new File(confDir, "resources"); propertiesFiles.addAll(Arrays.asList(findFiles(resourcesDir, ".properties"))); @@ -126,17 +100,17 @@ public class Executor { } File springDir = new File(confDir, "spring"); - File[] springFiles = findFiles(springDir, XML); + File[] springFiles = findFiles(springDir, EDEXModesUtil.XML); List springList = new ArrayList(); for (File f : springFiles) { String name = f.getName(); xmlFiles.add(name); - springList.add(XML_PATTERN.matcher(name).replaceAll("")); + springList.add(EDEXModesUtil.XML_PATTERN.matcher(name).replaceAll( + "")); } - EdexModesContainer emc = getModeFilter(confDir); String modeName = System.getProperty("edex.run.mode"); if (modeName != null && modeName.length() > 0) { @@ -148,27 +122,9 @@ public class Executor { System.out.println("EDEX site configuration: " + System.getProperty("aw.site.identifier")); - EdexMode edexMode = emc.getMode(modeName); - - if (edexMode != null && edexMode.isTemplate()) { - throw new UnsupportedOperationException(modeName - + " is a template mode, and is not bootable."); - } - - FilenameFilter mode = edexMode; - - if (mode == null) { - if (modeName == null || modeName.length() == 0) { - mode = new DefaultEdexMode(); - } else { - throw new UnsupportedOperationException( - "No EDEX run configuration specified in modes.xml for " - + modeName); - } - } - - List discoveredPlugins = extractSpringXmlFiles(pluginDirStr, - xmlFiles, mode); + List discoveredPlugins = EDEXModesUtil.extractSpringXmlFiles( + xmlFiles, + modeName); System.out.println(); System.out.println(" "); @@ -241,67 +197,4 @@ public class Executor { return sb.toString(); } - /** - * Populates files with a list of files that match in the specified - * directory - * - * Returns a list of plugins, etc - * - * @param jarDir - * @param files - * @return - * @throws IOException - */ - private static List extractSpringXmlFiles(String jarDir, - List files, FilenameFilter filter) throws IOException { - List retVal = new ArrayList(); - File jarDirFile = new File(jarDir); - File[] jars = jarDirFile.listFiles(); - - List jarList = new ArrayList(); - for (File p : jars) { - if (p.getName().endsWith(".jar")) { - JarFile jar = new JarFile(p); - jarList.add(jar); - } - } - - for (JarFile jar : jarList) { - Enumeration entries = jar.entries(); - while (entries.hasMoreElements()) { - JarEntry e = entries.nextElement(); - String name = e.getName(); - if (filter.accept(null, name)) { - files.add(name); - retVal.add(RES_SPRING_PATTERN.matcher( - XML_PATTERN.matcher(name).replaceAll("")) - .replaceAll("")); - } - } - - } - - return retVal; - } - - private static EdexModesContainer getModeFilter(File confDir) - throws IOException, JAXBException { - File file = new File(confDir.getPath(), MODES_FILE); - - FileReader reader = null; - Unmarshaller msh = null; - try { - JAXBContext jaxbContext = JAXBContext - .newInstance(EdexModesContainer.class); - msh = jaxbContext.createUnmarshaller(); - reader = new FileReader(file); - EdexModesContainer emc = (EdexModesContainer) msh.unmarshal(reader); - return emc; - } finally { - if (reader != null) { - PropertiesUtil.close(reader); - } - } - } - } diff --git a/tests/unit/com/raytheon/uf/edex/esb/camel/spring/EdexModeTest.java b/tests/unit/com/raytheon/uf/edex/core/modes/EdexModeTest.java similarity index 96% rename from tests/unit/com/raytheon/uf/edex/esb/camel/spring/EdexModeTest.java rename to tests/unit/com/raytheon/uf/edex/core/modes/EdexModeTest.java index 92e2edb2c7..9e498f5e36 100644 --- a/tests/unit/com/raytheon/uf/edex/esb/camel/spring/EdexModeTest.java +++ b/tests/unit/com/raytheon/uf/edex/core/modes/EdexModeTest.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.edex.esb.camel.spring; +package com.raytheon.uf.edex.core.modes; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -28,6 +28,8 @@ import java.util.Collections; import org.junit.Test; +import com.raytheon.uf.edex.core.modes.EdexMode; + /** * Test {@link EdexMode}.