Permalink
Browse files

Rigged broker REST interface into install and svc.

Pretty much the worst thing ever.
  • Loading branch information...
1 parent 0ba12cd commit 8334c9e43ef969ab775e51fdee0d43faa6587596 @labisso labisso committed Aug 11, 2010
@@ -12,6 +12,10 @@
<orderEntry type="library" name="ctxbroker-libs" level="project" />
<orderEntry type="module" module-name="common" />
<orderEntry type="library" name="test-libs" level="project" />
+ <orderEntry type="library" name="cxf-libs" level="project" />
+ <orderEntry type="module" module-name="ec2query" />
+ <orderEntry type="library" name="workspace-service-libs" level="project" />
+ <orderEntry type="module" module-name="authzdb" />
</component>
</module>
@@ -31,6 +31,7 @@
<root url="jar://$PROJECT_DIR$/lib/services/joda-time-1.6.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/wsdl4j-1.6.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/wstx-asl-3.2.8.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/gson-1.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
@@ -3,7 +3,7 @@ nimbus.ctxbroker.build.dir=build
nimbus.ctxbroker.build.dest=build/classes
nimbus.ctxbroker.src.dir=src
nimbus.ctxbroker.dist.dir=dist
-nimbus.ctxbroker.jar.name=nimbus-context-broker-2.2.jar
+nimbus.ctxbroker.jar.name=nimbus-context-broker.jar
# Dependencies
@@ -13,4 +13,8 @@ nimbus.ctxbroker.stubs.dir=wsdl/stubs
nimbus.ctxbroker.gar.dir=gar
nimbus.ctxbroker.stubs.dist=${nimbus.ctxbroker.stubs.dir}/dist
nimbus.ctxbroker.lib.dir=../lib/services
+
+# Compile dependencies from source tree
nimbus.messaging.query.dist.dir=../messaging/query/java/source/dist
+nimbus.service.api.dist.dir=../service-api/java/source/dist/
+nimbus.authz.dist.dir=../authzdb/dist
@@ -76,6 +76,14 @@
<include name="*.jar"/>
</fileset>
+ <fileset dir="${nimbus.authz.dist.dir}">
+ <include name="*.jar"/>
+ </fileset>
+
+ <fileset dir="${nimbus.service.api.dist.dir}">
+ <include name="*.jar"/>
+ </fileset>
+
<fileset dir="${nimbus.ctxbroker.lib.dir}">
<include name="*.jar"/>
</fileset>
@@ -68,6 +68,37 @@
</parameter>
</resourceParams>
</resource>
+ <resource
+ name="rest"
+ type="org.nimbustools.ctxbroker.rest.RestHttp">
+
+ <resourceParams>
+ <parameter>
+ <name>enabled</name>
+ <value>true</value>
+ </parameter>
+ <parameter>
+ <name>port</name>
+ <value>8446</value>
+ </parameter>
+ <parameter>
+ <name>springConfig</name>
+ <value>/some/path/services/etc/nimbus-context-broker/other/main.xml</value>
+ </parameter>
+ <parameter>
+ <name>keystoreLocation</name>
+ <value>/some/path/var/keystore.jks</value>
+ </parameter>
+ <parameter>
+ <name>keystorePassword</name>
+ <value>changeit</value>
+ </parameter>
+ <parameter>
+ <name>factory</name>
+ <value>org.globus.wsrf.jndi.BeanFactory</value>
+ </parameter>
+ </resourceParams>
+ </resource>
</service>
</jndiConfig>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Discover conf files. The conf files hold name/value pairs that are
+ brought into the XML files in this directory via Spring's nice properties
+ mechanism.
+
+ Concentrate all uses of PropertyPlaceholderConfigurer into this bean
+ config so that the install script can do token replacements for absolute
+ paths throughout the entire spring configuration by just running the
+ token replacement on this file.
+
+ Spring wants "//" in front of absolute filesystem paths so that is why
+ "/TOKEN" is used here instead of "TOKEN"
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+ <bean id="cumulusSettings"
+ class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+
+ <!-- grab some shared settings from the workspace-service cumulus.conf file,
+ will have to adjust for other deployment scenarios -->
+ <property name="location" value="$NIMBUS_HOME/services/etc/nimbus/workspace-service/cumulus.conf" />
+ <property name="placeholderPrefix" value="$CUMULUS{" />
+ </bean>
+</beans>
@@ -19,8 +19,26 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
- <bean id="userDetailsService" class="org.nimbustools.messaging.query.security.FileUserDetailsService">
- <constructor-arg value="/Users/david/foop/services/etc/nimbus/query/users.txt"/>
+ <bean id="other.AuthzDataSource"
+ class="org.apache.commons.dbcp.BasicDataSource">
+ <property name="driverClassName" value="org.sqlite.JDBC" />
+ <property name="maxActive" value="10" />
+ <property name="maxIdle" value="4" />
+ <property name="maxWait" value="2000" />
+ <property name="poolPreparedStatements" value="true" />
+
+ <property name="url"
+ value="jdbc:sqlite://$CUMULUS{cumulus.authz.db}" />
+ <property name="username" value="nimbus"/>
+ <property name="password" value="nimbus"/>
+ </bean>
+
+ <bean id="authzDBAdapter" class="org.nimbus.authz.AuthzDBAdapter">
+ <constructor-arg ref="other.AuthzDataSource"/>
+ </bean>
+
+ <bean id="userDetailsService" class="org.nimbustools.messaging.query.security.NimbusAuthzUserDetailsService">
+ <property name="authzDBAdapter" ref="authzDBAdapter" />
</bean>
<jaxrs:server id="ContextBroker" address="/ContextBroker/">
@@ -40,5 +58,11 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
</security:authentication-manager>
+ <!--
+ property sources are concentrated in this file
+ -->
+ <import resource="main.conflocator.xml"/>
+
+
</beans>
@@ -16,6 +16,7 @@
package org.nimbustools.ctxbroker.rest;
import org.apache.cxf.transport.servlet.CXFServlet;
+import org.globus.wsrf.jndi.Initializable;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
@@ -24,33 +25,29 @@
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.webapp.WebAppContext;
+import org.nimbustools.api.brain.NimbusXmlWebApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.filter.DelegatingFilterProxy;
import java.util.HashMap;
import java.util.Map;
-public class RestHttp {
+public class RestHttp implements Initializable {
+ //set by JNDI
private boolean enabled;
private int port;
private String springConfig;
private String keystoreLocation;
private String keystorePassword;
+
+
private Server server;
public RestHttp() {
}
- public RestHttp(String springConfig, int port,
- String keystoreLocation, String keystorePassword) {
- this.port = port;
- this.springConfig = springConfig;
- this.keystoreLocation = keystoreLocation;
- this.keystorePassword = keystorePassword;
- }
-
- public synchronized void startListening() throws Exception {
+ public void initialize() throws Exception {
if (!enabled) {
return;
@@ -84,7 +81,8 @@ public synchronized void startListening() throws Exception {
Context context = new Context(server, "/", Context.SESSIONS);
Map<String, String> initParams = new HashMap<String,String>();
- initParams.put("contextConfigLocation", springConfig);
+ initParams.put("contextConfigLocation", "file://" + springConfig);
+ initParams.put("contextClass", NimbusXmlWebApplicationContext.class.getCanonicalName());
context.setInitParams(initParams);
context.addEventListener(new ContextLoaderListener());
FilterHolder filterHolder = new FilterHolder(new DelegatingFilterProxy());
@@ -59,12 +59,17 @@
Constants.JNDI_SERVICES_BASE_NAME +
BrokerConstants.CTX_BROKER_PATH + "/home";
+ public static final String REST_HTTP =
+ Constants.JNDI_SERVICES_BASE_NAME +
+ BrokerConstants.CTX_BROKER_PATH + "/rest";
+
// -------------------------------------------------------------------------
// INSTANCE VARIABLES
// -------------------------------------------------------------------------
private final ContextBrokerHome home;
+ private final RestHttp restHttp;
// -------------------------------------------------------------------------
@@ -73,16 +78,7 @@
public ContextBrokerServiceImpl() throws Exception {
this.home = discoverHome();
-
- final String nimbusHome = System.getenv("NIMBUS_HOME");
- final File keystore = new File(nimbusHome, "var/keystore.jks");
-
-
- RestHttp http = new RestHttp("classpath:org/nimbustools/ctxbroker/rest/rest.xml", 8888,
- "file://"+keystore.getAbsolutePath(), "changeit");
- http.setEnabled(true);
- http.startListening();
-
+ this.restHttp = discoverRestHttp();
}
protected static ContextBrokerHome discoverHome() throws Exception {
@@ -106,6 +102,28 @@ protected static ContextBrokerHome discoverHome() throws Exception {
}
}
}
+
+ protected static RestHttp discoverRestHttp() throws Exception {
+
+ InitialContext ctx = null;
+ try {
+ ctx = new InitialContext();
+
+ final RestHttp rest =
+ (RestHttp) ctx.lookup(REST_HTTP);
+
+ if (rest == null) {
+ throw new Exception("null from JNDI for RestHttp (?)");
+ }
+
+ return rest;
+
+ } finally {
+ if (ctx != null) {
+ ctx.close();
+ }
+ }
+ }
// -------------------------------------------------------------------------
@@ -559,8 +559,8 @@ def perform_setup(self):
self.gtdir, log)
# and context broker
- gtcontainer.adjust_broker_config(ca_cert, ca_key, self.webdir,
- self.gtdir, log)
+ gtcontainer.adjust_broker_config(ca_cert, ca_key, self.keystore_path,
+ password, self.webdir, self.gtdir, log)
# run the web newconf script, if enabled
if self.config.getboolean(CONFIGSECTION, 'web.enabled'):
@@ -92,19 +92,34 @@ def adjust_host_cert(cert, key, basedir, gtdir, log):
exitcode, stdout, stderr)
log.debug("Activated host key file in GT container: %s" % cert)
-def adjust_broker_config(cacert, cakey, basedir, gtdir, log):
+def adjust_broker_config(cacert, cakey, keystore, keystore_pass, basedir, gtdir, log):
brokerconfig = get_brokerconfig_path(gtdir)
pathutil.ensure_file_exists(cacert, "CA certificate")
pathutil.ensure_file_exists(cakey, "CA private key")
pathutil.ensure_file_exists(brokerconfig, "Nimbus Context Broker config")
+ pathutil.ensure_file_exists(keystore, "Java keystore")
+
+ # is some BS
+ restbroker_xml = pathutil.pathjoin(gtdir,
+ 'etc/nimbus-context-broker/other/main.xml')
+ pathutil.ensure_file_exists(restbroker_xml,
+ "Context Broker REST interface config")
args = [brokerconfig, 'NimbusContextBroker', 'ctxBrokerBootstrapFactory',
'caCertPath', cacert, 'caKeyPath', cakey]
(exitcode, stdout, stderr) = javautil.run(basedir, log,
EXE_SERVICE_RESOURCE, args=args)
runutil.generic_bailout("Problem adjusting broker config",
exitcode, stdout, stderr)
+
+ args = [brokerconfig, 'NimbusContextBroker', 'rest',
+ 'keystoreLocation', keystore, 'keystorePassword', keystore_pass,
+ 'springConfig', restbroker_xml]
+ (exitcode, stdout, stderr) = javautil.run(basedir, log,
+ EXE_SERVICE_RESOURCE, args=args)
+ runutil.generic_bailout("Problem adjusting broker config",
+ exitcode, stdout, stderr)
log.debug("Ensured Context Broker CA config: %s" % brokerconfig)
def get_brokerconfig_path(gtdir):

0 comments on commit 8334c9e

Please sign in to comment.