Skip to content
Snippets Groups Projects
Commit 0ca3cc7e authored by felmer's avatar felmer
Browse files

SP-239, SWE-6: First approach which works only in dev environment.

SVN: 26452
parent ba23fe0a
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,9 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends ...@@ -38,6 +38,9 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends
ExposablePropertyPlaceholderConfigurer ExposablePropertyPlaceholderConfigurer
{ {
static final PluginType PLUGIN_TYPE_WEBAPPS = new PluginType("webapps",
BasicConstant.WEB_APPS_PROPERTY);
@Override @Override
protected void loadProperties(Properties properties) throws IOException protected void loadProperties(Properties properties) throws IOException
{ {
...@@ -51,7 +54,7 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends ...@@ -51,7 +54,7 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends
CustomImport.PropertyNames.CUSTOM_IMPORTS.getName()); CustomImport.PropertyNames.CUSTOM_IMPORTS.getName());
PluginType queryDatabases = new PluginType("query-databases", "query-databases"); PluginType queryDatabases = new PluginType("query-databases", "query-databases");
PluginType miscellaneous = new PluginType("miscellaneous", null); PluginType miscellaneous = new PluginType("miscellaneous", null);
PluginType webapps = new PluginType("webapps", BasicConstant.WEB_APPS_PROPERTY); PluginType webapps = PLUGIN_TYPE_WEBAPPS;
new CorePluginsInjector(ScannerType.AS, new IPluginType[] new CorePluginsInjector(ScannerType.AS, new IPluginType[]
{ maintenanceTasks, customImports, queryDatabases, miscellaneous, dssDataSources, { maintenanceTasks, customImports, queryDatabases, miscellaneous, dssDataSources,
......
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
package ch.systemsx.cisd.openbis.generic.server.coreplugin; package ch.systemsx.cisd.openbis.generic.server.coreplugin;
import static ch.systemsx.cisd.openbis.generic.server.coreplugin.CorePluginsInjectingPropertyPlaceholderConfigurer.PLUGIN_TYPE_WEBAPPS;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -25,12 +28,16 @@ import java.util.Properties; ...@@ -25,12 +28,16 @@ import java.util.Properties;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import ch.systemsx.cisd.base.unix.Unix;
import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.common.utilities.PropertyParametersUtil; import ch.systemsx.cisd.common.utilities.PropertyParametersUtil;
import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.common.utilities.PropertyUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin;
import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner;
import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner.ScannerType;
/** /**
* A class that injects web apps into jetty. * A class that injects web apps into jetty.
...@@ -39,6 +46,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; ...@@ -39,6 +46,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
*/ */
public class JettyWebAppPluginInjector public class JettyWebAppPluginInjector
{ {
private static final String WEBAPP_FOLDER = "webapp";
/** /**
* A utility class that generates a configuration file for a Jetty context for a webapp. * A utility class that generates a configuration file for a Jetty context for a webapp.
* *
...@@ -109,6 +118,8 @@ public class JettyWebAppPluginInjector ...@@ -109,6 +118,8 @@ public class JettyWebAppPluginInjector
public static final String WEB_APP_FOLDER_PROPERTY = "webapp-folder"; public static final String WEB_APP_FOLDER_PROPERTY = "webapp-folder";
private Map<String, File> webappToFoldersMap;
private static Map<String, Properties> extractWebappProperties(Properties props, private static Map<String, Properties> extractWebappProperties(Properties props,
List<String> webapps) List<String> webapps)
{ {
...@@ -130,6 +141,31 @@ public class JettyWebAppPluginInjector ...@@ -130,6 +141,31 @@ public class JettyWebAppPluginInjector
PropertyUtils.tryGetListInOriginalCase(props, BasicConstant.WEB_APPS_PROPERTY); PropertyUtils.tryGetListInOriginalCase(props, BasicConstant.WEB_APPS_PROPERTY);
webapps = (null == appList) ? Collections.<String> emptyList() : appList; webapps = (null == appList) ? Collections.<String> emptyList() : appList;
webappProperties = extractWebappProperties(props, webapps); webappProperties = extractWebappProperties(props, webapps);
webappToFoldersMap = new HashMap<String, File>();
String corePluginsFolder = props.getProperty("core-plugins-folder", "../../core-plugins");
CorePluginScanner scanner = new CorePluginScanner(corePluginsFolder, ScannerType.AS);
List<CorePlugin> plugins = scanner.scanForPlugins();
for (CorePlugin plugin : plugins)
{
File webappsFolder =
new File(corePluginsFolder, CorePluginScanner.constructPath(plugin,
ScannerType.AS, PLUGIN_TYPE_WEBAPPS));
if (webappsFolder.isDirectory())
{
File[] pluginFolders = webappsFolder.listFiles();
for (File folder : pluginFolders)
{
String webappName = folder.getName();
if (webappName.startsWith(".") == false)
{
String f =
webappProperties.get(webappName).getProperty(
WEB_APP_FOLDER_PROPERTY);
webappToFoldersMap.put(webappName, new File(folder, f));
}
}
}
}
} }
public void injectWebApps() public void injectWebApps()
...@@ -137,14 +173,29 @@ public class JettyWebAppPluginInjector ...@@ -137,14 +173,29 @@ public class JettyWebAppPluginInjector
logWebappsToInject(); logWebappsToInject();
// Leave if there is nothing to do // Leave if there is nothing to do
if (webapps.size() < 1) if (webapps.isEmpty())
{ {
return; return;
} }
if (false == isRunningUnderJetty()) if (false == isRunningUnderJetty())
{ {
// We are not running in Jetty. Log and then get out. List<File> targets = findInjectionTargets();
operationLog.error("Not running under jetty. Cannot inject webapps."); for (String webapp : webapps)
{
File folder = webappToFoldersMap.get(webapp);
String path = folder.getAbsolutePath();
for (File target : targets)
{
File link = new File(target, webapp);
if (link.exists() == false)
{
String linkPath = link.getAbsolutePath();
Unix.createSymbolicLink(path, linkPath);
operationLog.info("WebApp '" + webapp + "': Symbolic link " + linkPath
+ " -> " + path);
}
}
}
return; return;
} }
if (false == ensureContextFolderExists()) if (false == ensureContextFolderExists())
...@@ -159,6 +210,28 @@ public class JettyWebAppPluginInjector ...@@ -159,6 +210,28 @@ public class JettyWebAppPluginInjector
} }
} }
private List<File> findInjectionTargets()
{
List<File> list = new ArrayList<File>();
String jettyHome = System.getProperty("jetty.home");
if (jettyHome != null)
{
list.add(new File(jettyHome + "/webapps/openbis/" + WEBAPP_FOLDER));
} else
{
File[] files = new File("targets/www").listFiles();
for (File file : files)
{
File webappFolder = new File(file, WEBAPP_FOLDER);
if (webappFolder.isDirectory())
{
list.add(webappFolder);
}
}
}
return list;
}
private void logWebappsToInject() private void logWebappsToInject()
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
......
...@@ -59,6 +59,13 @@ public class CorePluginScanner implements ICorePluginResourceLoader ...@@ -59,6 +59,13 @@ public class CorePluginScanner implements ICorePluginResourceLoader
} }
} }
public static String constructPath(CorePlugin corePlugin, ScannerType scannerType,
IPluginType pluginType)
{
return corePlugin.getName() + "/" + corePlugin.getVersion() + "/"
+ scannerType.getSubFolderName() + "/" + pluginType.getSubFolderName();
}
private static final ISimpleLogger DEFAULT_LOGGER = new Log4jSimpleLogger(LogFactory.getLogger( private static final ISimpleLogger DEFAULT_LOGGER = new Log4jSimpleLogger(LogFactory.getLogger(
LogCategory.OPERATION, CorePluginScanner.class)); LogCategory.OPERATION, CorePluginScanner.class));
......
...@@ -232,12 +232,11 @@ public class CorePluginsInjector ...@@ -232,12 +232,11 @@ public class CorePluginsInjector
+ "' are not enabled."); + "' are not enabled.");
continue; continue;
} }
File dssFolder =
new File(corePluginsFolderPath, technology + "/" + corePlugin.getVersion()
+ "/" + scannerType.getSubFolderName());
for (IPluginType pluginType : pluginTypes) for (IPluginType pluginType : pluginTypes)
{ {
File file = new File(dssFolder, pluginType.getSubFolderName()); File file =
new File(corePluginsFolderPath, CorePluginScanner.constructPath(corePlugin,
scannerType, pluginType));
if (file.isDirectory()) if (file.isDirectory())
{ {
File[] pluginFolders = file.listFiles(new FilenameFilter() File[] pluginFolders = file.listFiles(new FilenameFilter()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment