From 5c2f0ab151868875a16ff51363987412804a9aeb Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Thu, 23 May 2013 18:42:11 -0500 Subject: [PATCH] Issue #2005 stop cave from starting if spring fails, prompt user if they want to restart Change-Id: I6b77e06c5737dab04c6c1a89cc2f5242a784bc53 Conflicts: cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF Former-commit-id: 329d9d1c6a43aac065f4750859186c84337b8b6b [formerly 329d9d1c6a43aac065f4750859186c84337b8b6b [formerly 6742f7dbcac39261d8bee4e055bb9e4eda66520d]] Former-commit-id: 5d1ecb3a5d015980703a1ccfbb4a3fea93806cb5 Former-commit-id: 2d1405b9c47708a378fdac153633a844bb27d8a0 --- .../META-INF/MANIFEST.MF | 1 + .../raytheon/uf/viz/spring/dm/Activator.java | 283 +++++++++--------- .../META-INF/MANIFEST.MF | 3 +- .../awips/AbstractCAVEComponent.java | 20 ++ .../viz/warnings/rsc/AbstractWWAResource.java | 1 - 5 files changed, 172 insertions(+), 136 deletions(-) diff --git a/cave/com.raytheon.uf.viz.spring.dm/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.spring.dm/META-INF/MANIFEST.MF index 4a82c091b6..2a71bb397d 100644 --- a/cave/com.raytheon.uf.viz.spring.dm/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.spring.dm/META-INF/MANIFEST.MF @@ -11,3 +11,4 @@ Require-Bundle: org.eclipse.core.runtime, com.raytheon.uf.common.comm;bundle-version="1.12.1174" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy +Export-Package: com.raytheon.uf.viz.spring.dm diff --git a/cave/com.raytheon.uf.viz.spring.dm/src/com/raytheon/uf/viz/spring/dm/Activator.java b/cave/com.raytheon.uf.viz.spring.dm/src/com/raytheon/uf/viz/spring/dm/Activator.java index ce8efe2ee1..bbf957123b 100644 --- a/cave/com.raytheon.uf.viz.spring.dm/src/com/raytheon/uf/viz/spring/dm/Activator.java +++ b/cave/com.raytheon.uf.viz.spring.dm/src/com/raytheon/uf/viz/spring/dm/Activator.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; @@ -34,6 +35,7 @@ import org.osgi.framework.Constants; * Jan 24, 2013 1522 bkowal Halt initialization if a p2 installation * has been started * Mar 05, 2013 1754 djohnson Catch exceptions and allow as much of the Spring container to boot as possible. + * May 23, 2013 2005 njensen Added springSuccess flag * * * @@ -42,102 +44,110 @@ import org.osgi.framework.Constants; */ public class Activator implements BundleActivator { - // The plug-in ID - public static final String PLUGIN_ID = "com.raytheon.uf.viz.spring.dm"; + // The plug-in ID + public static final String PLUGIN_ID = "com.raytheon.uf.viz.spring.dm"; - private static final String SPRING_PATH = "res" + IPath.SEPARATOR - + "spring"; + private static final String SPRING_PATH = "res" + IPath.SEPARATOR + + "spring"; - private static final String SPRING_FILE_EXT = "*.xml"; + private static final String SPRING_FILE_EXT = "*.xml"; - // The shared instance - private static Activator plugin; + private static final Pattern COMMA_SPLIT = Pattern.compile("[,]"); - /** - * The constructor - */ - public Activator() { - } + private static final Pattern SEMICOLON_SPLIT = Pattern.compile("[;]"); - /* - * (non-Javadoc) - * - * @see - * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) - */ - @Override + // The shared instance + private static Activator plugin; + + private boolean springSuccess = true; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + @Override public void start(BundleContext context) throws Exception { - if (this.isInstallOperation()) { - return; - } - plugin = this; + if (this.isInstallOperation()) { + return; + } + plugin = this; - Map contextMap = new HashMap(); - Set processing = new HashSet(); - Bundle[] bundles = context.getBundles(); - Map bundleMap = new HashMap(); - for (Bundle b : bundles) { - bundleMap.put(b.getSymbolicName(), b); - } - for (Bundle b : bundles) { - createContext(bundleMap, contextMap, b, processing); - } - } + Map contextMap = new HashMap(); + Set processing = new HashSet(); + Bundle[] bundles = context.getBundles(); + Map bundleMap = new HashMap(); + for (Bundle b : bundles) { + bundleMap.put(b.getSymbolicName(), b); + } + for (Bundle b : bundles) { + createContext(bundleMap, contextMap, b, processing); + } + } - private OSGIXmlApplicationContext createContext( - Map bundles, - Map contextMap, Bundle bundle, - Set processing) { - String bundleName = bundle.getSymbolicName(); - OSGIXmlApplicationContext appCtx = contextMap.get(bundleName); - if (contextMap.containsKey(bundleName) == false - && bundleName.contains(".edex.") == false) { - if (processing.contains(bundleName)) { - throw new RuntimeException( - "Found recursive spring dependency while processing plugins: " - + bundleName); - } - processing.add(bundleName); + private OSGIXmlApplicationContext createContext( + Map bundles, + Map contextMap, Bundle bundle, + Set processing) { + String bundleName = bundle.getSymbolicName(); + OSGIXmlApplicationContext appCtx = contextMap.get(bundleName); + if (contextMap.containsKey(bundleName) == false + && bundleName.contains(".edex.") == false) { + if (processing.contains(bundleName)) { + springSuccess = false; + throw new RuntimeException( + "Found recursive spring dependency while processing plugins: " + + bundleName); + } + processing.add(bundleName); - // No context created yet and not edex project, check for files - Enumeration entries = bundle.findEntries(SPRING_PATH, - SPRING_FILE_EXT, true); - if (entries != null) { - List files = new ArrayList(); - while (entries.hasMoreElements()) { - URL url = (URL) entries.nextElement(); - try { - url = FileLocator.toFileURL(url); - files.add(url.toString()); - } catch (IOException e) { - throw new RuntimeException( - "Error resolving spring file: " + url, e); - } - } - if (files.size() > 0) { - // Files found, check for dependencies - String requiredBundlesHeader = (String) bundle.getHeaders() - .get(Constants.REQUIRE_BUNDLE); - // Split comma separated string from MANIFEST - String[] requiredBundles = requiredBundlesHeader - .split("[,]"); - List parentContexts = new ArrayList(); - for (String requiredBndl : requiredBundles) { - // Extract bundle name which is first item in - // semicolon - // split list - String[] bndlParts = requiredBndl.split("[;]"); - Bundle reqBndl = bundles.get(bndlParts[0]); - if (reqBndl != null) { - // Found bundle, process context for bundle - OSGIXmlApplicationContext parent = createContext( - bundles, contextMap, reqBndl, processing); - if (parent != null) { - // Context found, add to list - parentContexts.add(parent); - } - } - } + // No context created yet and not edex project, check for files + Enumeration entries = bundle.findEntries(SPRING_PATH, + SPRING_FILE_EXT, true); + if (entries != null) { + List files = new ArrayList(); + while (entries.hasMoreElements()) { + URL url = (URL) entries.nextElement(); + try { + url = FileLocator.toFileURL(url); + files.add(url.toString()); + } catch (IOException e) { + throw new RuntimeException( + "Error resolving spring file: " + url, e); + } + } + if (files.size() > 0) { + // Files found, check for dependencies + String requiredBundlesHeader = (String) bundle.getHeaders() + .get(Constants.REQUIRE_BUNDLE); + // Split comma separated string from MANIFEST + String[] requiredBundles = COMMA_SPLIT + .split(requiredBundlesHeader); + List parentContexts = new ArrayList(); + for (String requiredBndl : requiredBundles) { + // Extract bundle name which is first item in + // semicolon + // split list + String[] bndlParts = SEMICOLON_SPLIT + .split(requiredBndl); + Bundle reqBndl = bundles.get(bndlParts[0]); + if (reqBndl != null) { + // Found bundle, process context for bundle + OSGIXmlApplicationContext parent = createContext( + bundles, contextMap, reqBndl, processing); + if (parent != null) { + // Context found, add to list + parentContexts.add(parent); + } + } + } try { if (parentContexts.size() > 0) { @@ -159,58 +169,63 @@ public class Activator implements BundleActivator { System.err .println("Errors booting the Spring container. CAVE will not be fully functional."); t.printStackTrace(); + springSuccess = false; } - } - } - contextMap.put(bundleName, appCtx); - } - processing.remove(bundleName); - return appCtx; - } + } + } + contextMap.put(bundleName, appCtx); + } + processing.remove(bundleName); + return appCtx; + } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) - */ - @Override + /* + * (non-Javadoc) + * + * @see + * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + @Override public void stop(BundleContext context) throws Exception { - plugin = null; - } + plugin = null; + } - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } - /** - * Based on the command line arguments, determine whether or not an Eclipse - * p2 repository will be installed - * - * @return true if an Eclipse p2 repository is going to be installed, false - * otherwise - */ - private boolean isInstallOperation() { - final String P2_DIRECTOR = "org.eclipse.equinox.p2.director"; + /** + * Based on the command line arguments, determine whether or not an Eclipse + * p2 repository will be installed + * + * @return true if an Eclipse p2 repository is going to be installed, false + * otherwise + */ + private boolean isInstallOperation() { + final String P2_DIRECTOR = "org.eclipse.equinox.p2.director"; - /** - * We look at the command line arguments instead of the program - * arguments (com.raytheon.uf.viz.application.ProgramArguments) because - * the command line arguments include almost everything that was passed - * as an argument to the Eclipse executable instead of just what CAVE is - * interested in. - */ - for (String argument : Platform.getCommandLineArgs()) { - if (P2_DIRECTOR.equals(argument)) { - return Boolean.TRUE; - } - } + /** + * We look at the command line arguments instead of the program + * arguments (com.raytheon.uf.viz.application.ProgramArguments) because + * the command line arguments include almost everything that was passed + * as an argument to the Eclipse executable instead of just what CAVE is + * interested in. + */ + for (String argument : Platform.getCommandLineArgs()) { + if (P2_DIRECTOR.equals(argument)) { + return Boolean.TRUE; + } + } - return Boolean.FALSE; - } + return Boolean.FALSE; + } + + public boolean isSpringInitSuccessful() { + return springSuccess; + } } diff --git a/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF index b5eb2acb91..4994939166 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.ui, com.raytheon.uf.viz.ui.menus;bundle-version="1.12.1174", com.raytheon.uf.viz.application;bundle-version="1.0.0", com.raytheon.viz.alerts;bundle-version="1.12.1174", - com.raytheon.uf.common.comm;bundle-version="1.12.1174" + com.raytheon.uf.common.comm;bundle-version="1.12.1174", + com.raytheon.uf.viz.spring.dm Bundle-ActivationPolicy: lazy Bundle-ClassPath: . Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java index 6fed3c1335..d0ac8ae473 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java @@ -37,6 +37,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.app.IApplication; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.internal.WorkbenchPlugin; @@ -95,6 +96,7 @@ import com.raytheon.viz.core.units.UnitRegistrar; * Apr 17, 2013 1786 mpduff startComponent now sets StatusHandlerFactory * Apr 23, 2013 #1939 randerso Allow serialization to complete initialization * before connecting to JMS to avoid deadlock + * May 23, 2013 #2005 njensen Shutdown on spring initialization errors * * * @@ -158,6 +160,24 @@ public abstract class AbstractCAVEComponent implements IStandaloneComponent { display = new Display(); } + // verify Spring successfully initialized, otherwise stop CAVE + if (!com.raytheon.uf.viz.spring.dm.Activator.getDefault() + .isSpringInitSuccessful()) { + String msg = "CAVE's Spring container did not initialize correctly and CAVE must shut down."; + boolean restart = false; + if (!nonui) { + msg += " Attempt to restart CAVE?"; + restart = MessageDialog.openQuestion(new Shell(display), + "Startup Error", msg); + } else { + System.err.println(msg); + } + if (restart) { + return IApplication.EXIT_RESTART; + } + return IApplication.EXIT_OK; + } + try { initializeLocalization(nonui); } catch (Exception e) { diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java index e043b53bfd..4dcb1b6077 100644 --- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java +++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java @@ -461,7 +461,6 @@ public abstract class AbstractWWAResource extends } protected void cleanupData(DataTime paintTime, DataTime[] descFrameTimes) { - System.out.println("entryMap size " + entryMap.size()); List framePeriods = new ArrayList( descFrameTimes.length); for (int i = 0; i < descFrameTimes.length; i++) {