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: 310597d856 [formerly 3d34764022] [formerly 410a00c72a] [formerly 310597d856 [formerly 3d34764022] [formerly 410a00c72a] [formerly 72df38075f [formerly 410a00c72a [formerly 76a844ed3158bcc80dc0d4b751cad83d39fcbbc4]]]]
Former-commit-id: 72df38075f
Former-commit-id: fa097589d0 [formerly e18f7b2380] [formerly d6d85c281b70c2e07827f44bc42368ab797e8062 [formerly c54fe467a3]]
Former-commit-id: e96fbe2c0a9f49c38dbe9b9eb76448f730afdb58 [formerly 3d592d0b38]
Former-commit-id: 143e160eae
This commit is contained in:
Brad Gonzales 2013-12-04 10:30:54 -06:00
parent 077ddd9818
commit d1fa8c738b
13 changed files with 247 additions and 159 deletions

View file

@ -236,7 +236,7 @@
<include>ebxml.*\.xml</include>
<includeMode>dataDeliveryTemplate</includeMode>
<include>datadelivery-wfo-cron.xml</include>
<include>bandwidth-datadelivery-edex-impl-wfo.xml</include>
<include>bandwidth-datadelivery-.*-wfo.xml</include>
<exclude>.*datadelivery.*-ncf.*</exclude>
<exclude>.*datadelivery.*-monolithic.*</exclude>
<exclude>harvester-*</exclude>
@ -246,7 +246,7 @@
<!-- Central Registry production mode -->
<include>ebxml.*\.xml</include>
<includeMode>dataDeliveryTemplate</includeMode>
<include>bandwidth-datadelivery-edex-impl-ncf.xml</include>
<include>bandwidth-datadelivery-.*-ncf.xml</include>
<exclude>.*datadelivery.*-wfo.*</exclude>
<exclude>.*datadelivery.*-monolithic.*</exclude>
</mode>
@ -298,7 +298,12 @@
<exclude>grid-metadata.xml</exclude>
<exclude>wxsrv-dataset-urn.xml</exclude>
</mode>
<mode name="inMemoryBandwidthManager">
<!-- This is not an edex runtime mode -->
<include>bandwidth-datadelivery-inmemory-impl.xml</include>
<include>bandwidth-datadelivery.xml</include>
<include>bandwidth-datadelivery-wfo.xml</include>
</mode>
<!-- modes listed below are not supported in a production setting, they
are for DEVELOPMENT purposes only -->
<mode name="devRegistry">
@ -306,6 +311,7 @@
<include>datadelivery-wfo-cron.xml</include>
<includeMode>dataDeliveryTemplate</includeMode>
<include>bandwidth-datadelivery-edex-impl-monolithic.xml</include>
<include>bandwidth-datadelivery-wfo.xml</include>
<exclude>.*datadelivery.*-ncf.*</exclude>
</mode>
<mode name="sbnSimulator">

View file

@ -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",

View file

@ -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.
*
* <pre>
*
@ -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.
*
* </pre>
*
@ -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);
}
}

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 5, 2013 2566 bgonzale Initial creation. Refactored from Executor.
*
* </pre>
*
* @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<String> extractSpringXmlFiles(List<String> files,
String modeName) throws IOException, JAXBException {
FilenameFilter filter = getModeFilter(modeName);
String pluginDirStr = PropertiesFactory.getInstance()
.getEnvProperties().getEnvValue("PLUGINDIR");
List<String> retVal = new ArrayList<String>();
File jarDirFile = new File(pluginDirStr);
File[] jars = jarDirFile.listFiles();
List<JarFile> jarList = new ArrayList<JarFile>(jars.length);
for (File p : jars) {
if (p.getName().endsWith(".jar")) {
JarFile jar = new JarFile(p);
jarList.add(jar);
}
}
for (JarFile jar : jarList) {
Enumeration<JarEntry> 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);
}
}
}
}

View file

@ -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.
*
* </pre>
*

View file

@ -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.
*
* </pre>
*

View file

@ -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.
*
* </pre>
*
@ -64,14 +64,9 @@ public class MonolithicBandwidthManagerCreator<T extends Time, C extends Coverag
static class MonolithicBandwidthManager<T extends Time, C extends Coverage>
extends NcfBandwidthManager<T, C> {
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.

View file

@ -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.
*
* </pre>
*
@ -75,14 +75,9 @@ public class NcfBandwidthManagerCreator<T extends Time, C extends Coverage> impl
*/
static class NcfBandwidthManager<T extends Time, C extends Coverage> extends EdexBandwidthManager<T, C> {
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.

View file

@ -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.
*
* </pre>
*
@ -139,6 +142,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage>
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<T, C> bandwidthDao;
@ -168,6 +173,33 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage>
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<String> fileList = new ArrayList<String>();
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<BandwidthAllocation> schedule(Subscription<T, C> subscription,
SortedSet<Integer> cycles) {
SortedSet<Calendar> retrievalTimes = bandwidthDaoUtil

View file

@ -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.
*
* </pre>
*
@ -65,13 +65,12 @@ class InMemoryBandwidthManager<T extends Time, C extends Coverage> 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

View file

@ -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.
*
* </pre>
*
@ -80,14 +80,9 @@ public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage>
static class WfoBandwidthManager<T extends Time, C extends Coverage>
extends EdexBandwidthManager<T, C> {
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<T, C> ncfBandwidthService = new NcfBandwidthService();

View file

@ -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.
*
* </pre>
*
@ -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<String> xmlFiles = new ArrayList<String>();
List<File> propertiesFiles = new ArrayList<File>();
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<String> springList = new ArrayList<String>();
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<String> discoveredPlugins = extractSpringXmlFiles(pluginDirStr,
xmlFiles, mode);
List<String> 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<String> extractSpringXmlFiles(String jarDir,
List<String> files, FilenameFilter filter) throws IOException {
List<String> retVal = new ArrayList<String>();
File jarDirFile = new File(jarDir);
File[] jars = jarDirFile.listFiles();
List<JarFile> jarList = new ArrayList<JarFile>();
for (File p : jars) {
if (p.getName().endsWith(".jar")) {
JarFile jar = new JarFile(p);
jarList.add(jar);
}
}
for (JarFile jar : jarList) {
Enumeration<JarEntry> 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);
}
}
}
}

View file

@ -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}.