teiid SVN: r1088 - in trunk: build/kit-embedded and 79 other directories.
by teiid-commitsï¼ lists.jboss.org
Author: rareddy
Date: 2009-06-26 18:06:04 -0400 (Fri, 26 Jun 2009)
New Revision: 1088
Added:
trunk/build/kit-embedded/bin/
trunk/build/kit-embedded/bin/run.bat
trunk/build/kit-embedded/bin/run.sh
trunk/build/kit-embedded/bin/shutdown.bat
trunk/build/kit-embedded/bin/shutdown.sh
trunk/build/kit-embedded/deploy/membership-file.properties
trunk/build/kit-embedded/deploy/membership-ldap.properties
trunk/client-jdbc/src/main/java/org/
trunk/client-jdbc/src/main/java/org/teiid/
trunk/client-jdbc/src/main/java/org/teiid/jdbc/
trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDataSource.java
trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java
trunk/common-core/src/main/java/com/metamatrix/common/util/JMXUtil.java
trunk/embedded/src/main/java/org/teiid/Server.java
trunk/embedded/src/main/java/org/teiid/ServerMBean.java
trunk/embedded/src/main/java/org/teiid/Shutdown.java
trunk/embedded/src/main/java/org/teiid/transport/
trunk/embedded/src/main/java/org/teiid/transport/AdminAuthorizationInterceptor.java
trunk/embedded/src/main/java/org/teiid/transport/ChannelListener.java
trunk/embedded/src/main/java/org/teiid/transport/ClientInstance.java
trunk/embedded/src/main/java/org/teiid/transport/LocalServerConnection.java
trunk/embedded/src/main/java/org/teiid/transport/LogonImpl.java
trunk/embedded/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
trunk/embedded/src/main/java/org/teiid/transport/SSLConfiguration.java
trunk/embedded/src/main/java/org/teiid/transport/ServerWorkItem.java
trunk/embedded/src/main/java/org/teiid/transport/SocketClientInstance.java
trunk/embedded/src/main/java/org/teiid/transport/SocketListener.java
trunk/embedded/src/main/java/org/teiid/transport/SocketTransport.java
trunk/embedded/src/test/java/com/metamatrix/platform/security/TestAdminAuthInterceptor.java
trunk/embedded/src/test/java/org/
trunk/embedded/src/test/java/org/teiid/
trunk/embedded/src/test/java/org/teiid/transport/
trunk/embedded/src/test/java/org/teiid/transport/TestCommSockets.java
trunk/embedded/src/test/java/org/teiid/transport/TestLogonImpl.java
trunk/embedded/src/test/java/org/teiid/transport/TestSocketRemoting.java
trunk/server/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java
trunk/server/src/main/java/com/metamatrix/common/config/ResourceNames.java
trunk/server/src/main/java/com/metamatrix/common/config/model/
trunk/server/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java
trunk/server/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java
trunk/server/src/main/java/com/metamatrix/common/config/reader/
trunk/server/src/main/java/com/metamatrix/common/config/reader/CurrentConfigurationReader.java
trunk/server/src/main/java/com/metamatrix/common/config/reader/PropertiesConfigurationReader.java
trunk/server/src/main/java/com/metamatrix/common/util/CommonPropertyNames.java
trunk/server/src/test/java/com/metamatrix/common/config/
trunk/server/src/test/java/com/metamatrix/common/config/model/
trunk/server/src/test/java/com/metamatrix/common/config/model/TestComponentCryptoUtil.java
trunk/server/src/test/java/com/metamatrix/common/config/model/TestPropertyValidation.java
Removed:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactory.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedSQLException.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMServerConnection.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/ResourceNames.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/CurrentConfigurationReader.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/PropertiesConfigurationReader.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/CommonPropertyNames.java
trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestComponentCryptoUtil.java
trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestPropertyValidation.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnection.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/transport/
trunk/embedded/src/main/java/com/metamatrix/platform/security/authorization/spi/
trunk/engine/src/main/java/com/metamatrix/common/application/DQPGuiceModule.java
trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServiceInterface.java
trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServicePropertyNames.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/ChannelListener.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SSLAwareChannelHandler.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/AdminAuthorizationInterceptor.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ClientInstance.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/LogonImpl.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketClientInstance.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketListener.java
trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java
trunk/server/src/test/java/com/metamatrix/common/comm/platform/server/TestAdminAuthInterceptor.java
trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java
trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestLogonImpl.java
trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestSocketRemoting.java
Modified:
trunk/build/assembly/embedded/build-configuration.xml
trunk/build/assembly/embedded/embedded-dist.xml
trunk/build/kit-embedded/deploy.properties
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BaseDriver.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMConnection.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDriver.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMConnection.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMDataSource.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/util/TestMMJDBCURL.java
trunk/client/src/main/java/com/metamatrix/admin/api/core/Admin.java
trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedConfigAdmin.java
trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedMonitoringAdmin.java
trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedRuntimeStateAdmin.java
trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedSecurityAdmin.java
trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnection.java
trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
trunk/client/src/main/java/com/metamatrix/common/comm/platform/client/ServerAdminFactory.java
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java
trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigurationPropertyNames.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/LogConstants.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/crypto/keymanage/FilePasswordConverter.java
trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties
trunk/embedded/pom.xml
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/Log4JUtil.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/LogConfigurationProvider.java
trunk/embedded/src/main/java/com/metamatrix/jdbc/LogListernerProvider.java
trunk/embedded/src/main/java/com/metamatrix/platform/security/authorization/service/AuthorizationServiceImpl.java
trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/service/MembershipServiceImpl.java
trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/spi/file/FileMembershipDomain.java
trunk/embedded/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java
trunk/embedded/src/main/resources/com/metamatrix/platform/i18n.properties
trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/TestEmbeddedConfigSource.java
trunk/embedded/src/test/java/com/metamatrix/platform/security/membership/service/TestMembershipServiceImpl.java
trunk/engine/src/main/java/com/metamatrix/common/application/Application.java
trunk/engine/src/main/java/com/metamatrix/common/application/DQPConfigSource.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/storage/file/FileStorageManager.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/AuditMessage.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/AuthorizationService.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/DQPServiceNames.java
trunk/engine/src/main/java/com/metamatrix/dqp/util/LogConstants.java
trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/MembershipServiceInterface.java
trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
trunk/engine/src/test/java/com/metamatrix/dqp/config/TestDQPLauncher.java
trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeAuthorizationService.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/server/pom.xml
trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
trunk/server/src/main/java/com/metamatrix/platform/security/api/service/MembershipServiceInterface.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java
trunk/server/src/main/java/com/metamatrix/server/admin/apiimpl/RuntimeMetadataAdminAPIImpl.java
trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java
trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformAuthorizationService.java
trunk/test-integration/pom.xml
trunk/test-integration/src/test/java/com/metamatrix/cdk/TestLoopbackConnector.java
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestCase3473.java
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestMMDatabaseMetaData.java
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestXQueryServices.java
trunk/test-integration/src/test/java/com/metamatrix/systemmodel/TestPartsDatabaseMetadata.java
trunk/test-integration/src/test/java/com/metamatrix/systemmodel/TestResultSetMetadata.java
trunk/test-integration/src/test/java/com/metamatrix/systemmodel/TestSystemVirtualModel.java
trunk/test-integration/src/test/java/com/metamatrix/systemmodel/TestVirtualDocWithVirtualProc.java
trunk/test-integration/src/test/java/org/teiid/connector/metadata/runtime/TestMetadataInConnector.java
Log:
TEIID-664, TEIID-665, TEIID-666, TEIID-680, TEIID259, TEIID-601, TEIID-259
1) Added socket code to the embedded, enabled the socket transport
2) Wired Membership, Authentication, Session services with configuration and rest of the engine
3) Collapsed EmbeddedConfigSource, EmbeddedGuiceModule and DQPGuiceModule into single EmbeddedguiceModule
4) Removed EmbeddedConnectionFactory, promoted the use of ServerConnection on the embedded. This made few classes collapse.
5) Created separate Teiid Driver, Teiid DataSource
6) Created initial Server kit
Modified: trunk/build/assembly/embedded/build-configuration.xml
===================================================================
--- trunk/build/assembly/embedded/build-configuration.xml 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/build/assembly/embedded/build-configuration.xml 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,19 +1,19 @@
<project default="main" name="teiid-configuration-build" basedir=".">
-
+
<property name="kit.dir" value="${basedir}/target/kit-embedded"/>
<property name="extensions.dir" value="${basedir}/target/dependency"/>
-
-
+
+
<target name="main" >
<copy todir="${kit.dir}">
<fileset dir="${basedir}/kit-embedded"/>
- </copy>
-
+ </copy>
+
<!-- unzip the connector zip files in to directory and move the jar files into extensions directory -->
<unzip dest="${extensions.dir}/unzipped">
<fileset dir="${extensions.dir}">
- <include name="*.zip"/>
+ <include name="*.zip"/>
</fileset>
</unzip>
<move todir="${kit.dir}/extensions">
@@ -21,16 +21,33 @@
<include name="**/*.jar"/>
</fileset>
</move>
-
- <!-- add all the cdk files, and then add the combined fragment to the config.xml -->
- <concat destfile="${extensions.dir}/unzipped/all-cdks.xml">
- <fileset dir="${extensions.dir}/unzipped" includes="connector-*.xml"/>
- </concat>
-
- <loadfile property="connector-types-fragment" srcFile="${extensions.dir}/unzipped/all-cdks.xml"/>
- <replace file="${kit.dir}/deploy/configuration.xml" token="${connector-types-fragment-fill-in}" value="${connector-types-fragment}"/>
- <mkdir dir="${kit.dir}/log"/>
- </target>
-
+ <!-- add all the cdk files, and then add the combined fragment to the config.xml -->
+ <concat destfile="${extensions.dir}/unzipped/all-cdks.xml">
+ <fileset dir="${extensions.dir}/unzipped" includes="connector-*.xml"/>
+ </concat>
+
+ <loadfile property="connector-types-fragment" srcFile="${extensions.dir}/unzipped/all-cdks.xml"/>
+ <replace file="${kit.dir}/deploy/configuration.xml" token="${connector-types-fragment-fill-in}" value="${connector-types-fragment}"/>
+
+ <mkdir dir="${kit.dir}/log"/>
+ <mkdir dir="${kit.dir}/work"/>
+
+ <antcall target="chmod"/>
+ </target>
+
+ <target name="set.os">
+ <condition property="UnixOS">
+ <os family="unix"/>
+ </condition>
+ <condition property="WinOS">
+ <os family="windows"/>
+ </condition>
+ </target>
+
+ <target name="chmod" depends="set.os" if="UnixOS">
+ <fixcrlf srcdir="${kit.dir}/bin" eol="lf" eof="remove" includes="**/*.sh"/>
+ <chmod dir="${kit.dir}/bin" perm="ugo+rx" includes="**/*.sh"/>
+ </target>
+
</project>
\ No newline at end of file
Modified: trunk/build/assembly/embedded/embedded-dist.xml
===================================================================
--- trunk/build/assembly/embedded/embedded-dist.xml 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/build/assembly/embedded/embedded-dist.xml 2009-06-26 22:06:04 UTC (rev 1088)
@@ -17,7 +17,7 @@
<includes>
<include>teiid-${version}-client.jar</include>
</includes>
- <outputDirectory>/</outputDirectory>
+ <outputDirectory>client</outputDirectory>
</fileSet>
<fileSet>
@@ -37,7 +37,7 @@
<includes>
<include>teiid-hibernate-dialect-${version}.jar</include>
</includes>
- <outputDirectory>hibernate</outputDirectory>
+ <outputDirectory>client</outputDirectory>
</fileSet>
<fileSet>
Added: trunk/build/kit-embedded/bin/run.bat
===================================================================
--- trunk/build/kit-embedded/bin/run.bat (rev 0)
+++ trunk/build/kit-embedded/bin/run.bat 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,76 @@
+@echo off
+rem -------------------------------------------------------------------------
+rem Teiid Bootstrap Script for Windows (borrowed & modified from JBoss AS)
+rem -------------------------------------------------------------------------
+
+
+@if not "%ECHO%" == "" echo %ECHO%
+@if "%OS%" == "Windows_NT" setlocal
+
+if "%OS%" == "Windows_NT" (
+ set "DIRNAME=%~dp0%"
+) else (
+ set DIRNAME=.\
+)
+
+pushd %DIRNAME%..
+if "x%TEIID_HOME%" == "x" (
+ set "TEIID_HOME=%CD%"
+)
+popd
+
+set DIRNAME=
+
+if "x%JAVA_HOME%" == "x" (
+ set JAVA=java
+ echo JAVA_HOME is not set. Unexpected results may occur.
+ echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
+) else (
+ set "JAVA=%JAVA_HOME%\bin\java"
+ if exist "%JAVA_HOME%\lib\tools.jar" (
+ set "JAVAC_JAR=%JAVA_HOME%\lib\tools.jar"
+ )
+)
+
+set TEIID_CLASSPATH=%TEIID_HOME%\lib\patches\*;%TEIID_HOME%\deploy;%TEIID_HOME%\client\*;%TEIID_HOME%\lib\*;
+
+rem JVM memory allocation pool parameters. Modify as appropriate.
+set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -XX:MaxPermSize=256m
+
+rem Add JMX support
+set JMX_PORT=9999
+set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=%JMX_PORT% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
+
+rem With Sun JVMs reduce the RMI GCs to once per hour
+set JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
+
+rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.
+rem set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
+
+echo ===============================================================================
+echo.
+echo Teiid Bootstrap Environment
+echo.
+echo TEIID_HOME: %TEIID_HOME%
+echo.
+echo JAVA: %JAVA%
+echo.
+echo JAVA_OPTS: %JAVA_OPTS%
+echo.
+echo CLASSPATH: %TEIID_CLASSPATH%
+echo.
+echo ===============================================================================
+echo.
+
+:RESTART
+"%JAVA%" %JAVA_OPTS% ^
+ -classpath "%JBOSS_CLASSPATH%" ^
+ -server ^
+ org.teiid.Server %TEIID_HOME%\deploy.properties %*
+
+if ERRORLEVEL 10 goto RESTART
+
+:END
+if "x%NOPAUSE%" == "x" pause
+
+:END_NO_PAUSE
Added: trunk/build/kit-embedded/bin/run.sh
===================================================================
--- trunk/build/kit-embedded/bin/run.sh (rev 0)
+++ trunk/build/kit-embedded/bin/run.sh 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,132 @@
+#!/bin/sh
+### ====================================================================== ###
+## ##
+## Teiid Bootstrap Script ##
+## (script borrowed from JBossAS) ##
+### ====================================================================== ###
+
+DIRNAME=`dirname $0`
+PROGNAME=`basename $0`
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+linux=false;
+case "`uname`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+
+ Linux)
+ linux=true
+ ;;
+esac
+
+# Add JMX support
+JMX_PORT=9999
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
+
+# JPDA options. Uncomment and modify as appropriate to enable remote debugging.
+# JAVA_OPTS=$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
+
+# Force IPv4 on Linux systems since IPv6 doesn't work correctly with jdk5 and lower
+if [ "$linux" = "true" ]; then
+ JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
+fi
+
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$TEIID_HOME" ] &&
+ TEIID_HOME=`cygpath --unix "$TEIID_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Setup TEIID_HOME
+if [ "x$TEIID_HOME" = "x" ]; then
+ # get the full path (without any relative bits)
+ TEIID_HOME=`cd $DIRNAME/..; pwd`
+fi
+export TEIID_HOME
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+TEIID_CLASSPATH="$TEIID_HOME/lib/patches/*:$TEIID_HOME/deploy:$TEIID_HOME/client/*:$TEIID_HOME/lib/*"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ TEIID_HOME=`cygpath --path --windows "$TEIID_HOME"`
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ TEIID_CLASSPATH=`cygpath --path --windows "$TEIID_CLASSPATH"`
+fi
+
+# Display our environment
+echo "========================================================================="
+echo ""
+echo " Teiid Bootstrap Environment"
+echo ""
+echo " TEIID_HOME: $TEIID_HOME"
+echo ""
+echo " JAVA: $JAVA"
+echo ""
+echo " JAVA_OPTS: $JAVA_OPTS"
+echo ""
+echo " CLASSPATH: $TEIID_CLASSPATH"
+echo ""
+echo "========================================================================="
+echo ""
+
+while true; do
+ if [ "x$LAUNCH_TEIID_IN_BACKGROUND" = "x" ]; then
+ # Execute the JVM in the foreground
+ "$JAVA" $JAVA_OPTS \
+ -classpath "$TEIID_CLASSPATH" \
+ -server \
+ org.teiid.Server $TEIID_HOME/deploy.properties "$@"
+ _STATUS=$?
+ else
+ # Execute the JVM in the background
+ "$JAVA" $JAVA_OPTS \
+ -classpath "$TEIID_CLASSPATH" \
+ -server \
+ org.teiid.Server $TEIID_HOME/deploy.properties "$@" &
+ _PID=$!
+ echo $_PID > $TEIID_HOME/work/teiid.pid
+ # Trap common signals and relay them to the process
+ trap "kill -HUP $_PID" HUP
+ trap "kill -TERM $_PID" INT
+ trap "kill -QUIT $_PID" QUIT
+ trap "kill -PIPE $_PID" PIPE
+ trap "kill -TERM $_PID" TERM
+ # Wait until the background process exits
+ WAIT_STATUS=128
+ while [ "$WAIT_STATUS" -ge 128 ]; do
+ wait $_PID 2>/dev/null
+ WAIT_STATUS=$?
+ if [ "${WAIT_STATUS}" -gt 128 ]; then
+ SIGNAL=`expr ${WAIT_STATUS} - 128`
+ SIGNAL_NAME=`kill -l ${SIGNAL}`
+ echo "*** Teiid process (${_PID}) received ${SIGNAL_NAME} signal ***" >&2
+ fi
+ done
+ if [ "${WAIT_STATUS}" -lt 127 ]; then
+ _STATUS=$WAIT_STATUS
+ else
+ _STATUS=0
+ fi
+ fi
+
+ if [ "$_STATUS" -eq 10 ]; then
+ echo "Restarting ..."
+ else
+ exit $_STATUS
+ fi
+done
+
Added: trunk/build/kit-embedded/bin/shutdown.bat
===================================================================
--- trunk/build/kit-embedded/bin/shutdown.bat (rev 0)
+++ trunk/build/kit-embedded/bin/shutdown.bat 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,75 @@
+@echo off
+rem -------------------------------------------------------------------------
+rem Teiid Bootstrap Script for Windows (borrowed & modified from JBoss AS)
+rem -------------------------------------------------------------------------
+
+
+@if not "%ECHO%" == "" echo %ECHO%
+@if "%OS%" == "Windows_NT" setlocal
+
+if "%OS%" == "Windows_NT" (
+ set "DIRNAME=%~dp0%"
+) else (
+ set DIRNAME=.\
+)
+
+pushd %DIRNAME%..
+if "x%TEIID_HOME%" == "x" (
+ set "TEIID_HOME=%CD%"
+)
+popd
+
+set DIRNAME=
+
+if "x%JAVA_HOME%" == "x" (
+ set JAVA=java
+ echo JAVA_HOME is not set. Unexpected results may occur.
+ echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
+) else (
+ set "JAVA=%JAVA_HOME%\bin\java"
+ if exist "%JAVA_HOME%\lib\tools.jar" (
+ set "JAVAC_JAR=%JAVA_HOME%\lib\tools.jar"
+ )
+)
+
+set TEIID_CLASSPATH=%TEIID_HOME%\lib\patches\*;%TEIID_HOME%\deploy;%TEIID_HOME%\client\*;%TEIID_HOME%\lib\*;
+
+rem JVM memory allocation pool parameters. Modify as appropriate.
+set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -XX:MaxPermSize=256m
+
+rem Add JMX support
+set JMX_PORT=9999
+
+rem With Sun JVMs reduce the RMI GCs to once per hour
+set JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
+
+rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.
+rem set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
+
+echo ===============================================================================
+echo.
+echo Teiid Bootstrap Environment
+echo.
+echo TEIID_HOME: %TEIID_HOME%
+echo.
+echo JAVA: %JAVA%
+echo.
+echo JAVA_OPTS: %JAVA_OPTS%
+echo.
+echo CLASSPATH: %TEIID_CLASSPATH%
+echo.
+echo ===============================================================================
+echo.
+
+:RESTART
+"%JAVA%" %JAVA_OPTS% ^
+ -classpath "%JBOSS_CLASSPATH%" ^
+ -server ^
+ org.teiid.Shutdown %TEIID_HOME%\deploy.properties %JMX_PORT% %*
+
+if ERRORLEVEL 10 goto RESTART
+
+:END
+if "x%NOPAUSE%" == "x" pause
+
+:END_NO_PAUSE
Added: trunk/build/kit-embedded/bin/shutdown.sh
===================================================================
--- trunk/build/kit-embedded/bin/shutdown.sh (rev 0)
+++ trunk/build/kit-embedded/bin/shutdown.sh 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,98 @@
+#!/bin/sh
+### ====================================================================== ###
+## ##
+## Teiid Bootstrap Script ##
+## (script borrowed from JBossAS) ##
+### ====================================================================== ###
+
+DIRNAME=`dirname $0`
+PROGNAME=`basename $0`
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+linux=false;
+case "`uname`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+
+ Linux)
+ linux=true
+ ;;
+esac
+
+# Add JMX support
+JMX_PORT=9999
+
+# JPDA options. Uncomment and modify as appropriate to enable remote debugging.
+# JAVA_OPTS=$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
+
+# Force IPv4 on Linux systems since IPv6 doesn't work correctly with jdk5 and lower
+if [ "$linux" = "true" ]; then
+ JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
+fi
+
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$TEIID_HOME" ] &&
+ TEIID_HOME=`cygpath --unix "$TEIID_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Setup TEIID_HOME
+if [ "x$TEIID_HOME" = "x" ]; then
+ # get the full path (without any relative bits)
+ TEIID_HOME=`cd $DIRNAME/..; pwd`
+fi
+export TEIID_HOME
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+TEIID_CLASSPATH="$TEIID_HOME/lib/patches/*:$TEIID_HOME/deploy:$TEIID_HOME/client/*:$TEIID_HOME/lib/*"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ TEIID_HOME=`cygpath --path --windows "$TEIID_HOME"`
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ TEIID_CLASSPATH=`cygpath --path --windows "$TEIID_CLASSPATH"`
+fi
+
+# Display our environment
+echo "========================================================================="
+echo ""
+echo " Teiid Bootstrap Environment"
+echo ""
+echo " TEIID_HOME: $TEIID_HOME"
+echo ""
+echo " JAVA: $JAVA"
+echo ""
+echo " JAVA_OPTS: $JAVA_OPTS"
+echo ""
+echo " CLASSPATH: $TEIID_CLASSPATH"
+echo ""
+echo "========================================================================="
+echo ""
+
+while true; do
+ "$JAVA" $JAVA_OPTS \
+ -classpath "$TEIID_CLASSPATH" \
+ -server \
+ org.teiid.Shutdown $TEIID_HOME/deploy.properties $JMX_PORT "$@"
+ _STATUS=$?
+
+ if [ "$_STATUS" -eq 10 ]; then
+ echo "Restarting ..."
+ else
+ exit $_STATUS
+ fi
+done
+
Added: trunk/build/kit-embedded/deploy/membership-file.properties
===================================================================
--- trunk/build/kit-embedded/deploy/membership-file.properties (rev 0)
+++ trunk/build/kit-embedded/deploy/membership-file.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,11 @@
+#File based membership domain configuration properties
+
+#Location of the properties file containing user name and password entries.
+usersFile=users.properties
+
+#Location of the properties file containing group assignments
+groupsFile=groups.properties
+
+#Check passwords against the users file.
+checkPassword=true
+
Property changes on: trunk/build/kit-embedded/deploy/membership-file.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/build/kit-embedded/deploy/membership-ldap.properties
===================================================================
--- trunk/build/kit-embedded/deploy/membership-ldap.properties (rev 0)
+++ trunk/build/kit-embedded/deploy/membership-ldap.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,49 @@
+# Configuration file for LDAP membership domain
+
+activate=true
+
+#Full LDAP URL (mandatory)
+ldapURL=
+
+#Bind account password for group lookup.
+ldapAdmin.password=
+
+#The attribute(s) that uniquely identifies a user.
+users.displayName.attribute = uid
+
+#The search filter(s) to apply to each users root context.
+users.searchFilter=(objectclass=*)
+
+#Specifies the context(s) to use when searching for users.(mandatory)
+users.rootContext=
+
+#Bind account DN for group lookup.
+ldapAdmin.dn=
+
+#Attribute(s) that appears on each user that identifies group membership.
+users.memberOf.attribute=
+
+#The attribute(s) that uniquely identifies a group.
+groups.displayName.attribute=
+
+#How far down the directory tree to search each users root context.
+users.searchScope=SUBTREE_SCOPE
+
+#Specifies the context(s) to use when searching for groups.(mandatory)
+groups.rootContext=
+
+# Membership Domain Class Name
+AuthDomainClass=com.metamatrix.platform.security.membership.spi.ldap.LDAPMembershipDomain
+
+#The search filter(s) to apply to each groups root context
+groups.searchFilter=(objectclass=*)
+
+#How far down the directory tree to search each groups root context.
+groups.searchScope=SUBTREE_SCOPE
+
+#Time to wait for LDAP operations to complete.
+txnTimeoutInMillis=
+
+#The attribute(s) that contains the members of the group.
+groups.groupMember.attribute=
+
Property changes on: trunk/build/kit-embedded/deploy/membership-ldap.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/build/kit-embedded/deploy.properties
===================================================================
--- trunk/build/kit-embedded/deploy.properties 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/build/kit-embedded/deploy.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -2,6 +2,9 @@
# This is properties file used for bootstrap Teiid embedded for loading
#
+# name of the process that uniquely identifies this process( if ignored one will be assigned)
+processName=localhost
+
#Path to the Teiid Configuration file
dqp.configFile=./deploy/configuration.xml
@@ -76,4 +79,67 @@
#ResultSetCacheMaxAge=3600000
#Defines whether caching is restricted to a specific session ('session') or a specific VDB version ('vdb'). (default vdb)
-#ResultSetCacheScope=vdb
\ No newline at end of file
+#ResultSetCacheScope=vdb
+
+#
+# Session Service Settings
+#
+
+#Maximum number of sessions allowed by the system
+session.maxSessions=5000
+
+#Max allowed time before the session is timed out between two ping calls
+session.timeoutInMilli=1800000
+
+#
+# Membership Service Settings (handles the authentication of the user)
+#
+
+membership.enabled=true
+membership.superUser=admin
+membership.superUserPassword=teiid
+#Membership Domain Order (comma separated list of domains to authenticate user. ex: file, ldap)
+membership.DomainOrder=file
+#Allow connections only from specified hosts
+#membership.allowedHosts=
+
+# File Membership Domain Settings (activate, Membership Domain Class Name, Property file for configuration)
+file.activate=false
+file.AuthDomainClass=com.metamatrix.platform.security.membership.spi.file.FileMembershipDomain
+file.propertiesFile=./deploy/membership-file.properties
+
+# LDAP Membership Domain Settings (activate, Membership Domain Class Name, Property file for configuration)
+#ldap.activate=false
+#ldap.AuthDomainClass=com.metamatrix.platform.security.membership.spi.ldap.LDAPMembershipDomain
+#ldap.propertiesFile=./deploy/membership-ldap.properties
+
+#
+# Authorization Service Settings
+#
+
+# Enable entitlements (data, admin)
+entitlements.enabled=false
+
+
+#
+# Server Settings (Socket transport)
+#
+
+server.portNumber=31000
+server.bindAddress=localhost
+#server.maxSocketThreads=15
+#server.inputBufferSize=0
+#server.outputBufferSize=0
+
+
+# SSL Settings
+#ssl.enabled=true
+#ssl.protocol=SSLv3
+#ssl.authenticationMode=1-way
+#ssl.keymanagementalgorithm=
+#ssl.keystore.filename=teiid.keystore
+#ssl.keystore.Password=changeme
+#ssl.keystoretype=JKS
+#ssl.truststore.filename=teiid.truststore
+#ssl.truststore.Password=changeme
+#client.encryption.enabled=true
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/core/Admin.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/core/Admin.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/core/Admin.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,12 +22,20 @@
package com.metamatrix.admin.api.core;
+import com.metamatrix.admin.RolesAllowed;
+import com.metamatrix.admin.api.server.AdminRoles;
+
/**
* Marker interface for all MetaMatrix administration - core.
*
* @since 4.3
*/
public interface Admin extends CoreConfigAdmin, CoreMonitoringAdmin, CoreRuntimeStateAdmin, CoreSecurityAdmin {
-
+ /**
+ * Closes connection.
+ * @since 4.3
+ */
+ @RolesAllowed(value=AdminRoles.RoleName.ANONYMOUS)
+ void close();
}
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedConfigAdmin.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedConfigAdmin.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedConfigAdmin.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,13 +22,16 @@
package com.metamatrix.admin.api.embedded;
+import com.metamatrix.admin.RolesAllowed;
import com.metamatrix.admin.api.core.CoreConfigAdmin;
import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.admin.api.server.AdminRoles;
/**
* @since 4.3
*/
+(a)RolesAllowed(value=AdminRoles.RoleName.ADMIN_SYSTEM)
public interface EmbeddedConfigAdmin extends CoreConfigAdmin {
/**
* Indicates that an extension module has changed
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedMonitoringAdmin.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedMonitoringAdmin.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedMonitoringAdmin.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,12 +22,15 @@
package com.metamatrix.admin.api.embedded;
+import com.metamatrix.admin.RolesAllowed;
import com.metamatrix.admin.api.core.CoreMonitoringAdmin;
+import com.metamatrix.admin.api.server.AdminRoles;
/**
* @since 4.3
*/
+(a)RolesAllowed(value=AdminRoles.RoleName.ADMIN_READONLY)
public interface EmbeddedMonitoringAdmin extends
CoreMonitoringAdmin {
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedRuntimeStateAdmin.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedRuntimeStateAdmin.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedRuntimeStateAdmin.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,14 +22,17 @@
package com.metamatrix.admin.api.embedded;
+import com.metamatrix.admin.RolesAllowed;
import com.metamatrix.admin.api.core.CoreRuntimeStateAdmin;
import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.admin.api.server.AdminRoles;
/**
* @since 4.3
*/
+(a)RolesAllowed(value=AdminRoles.RoleName.ADMIN_PRODUCT)
public interface EmbeddedRuntimeStateAdmin extends CoreRuntimeStateAdmin {
/**
Modified: trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedSecurityAdmin.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedSecurityAdmin.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/admin/api/embedded/EmbeddedSecurityAdmin.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,12 +22,15 @@
package com.metamatrix.admin.api.embedded;
+import com.metamatrix.admin.RolesAllowed;
import com.metamatrix.admin.api.core.CoreSecurityAdmin;
+import com.metamatrix.admin.api.server.AdminRoles;
/**
* @since 4.3
*/
+(a)RolesAllowed(value=AdminRoles.RoleName.ADMIN_SYSTEM)
public interface EmbeddedSecurityAdmin extends
CoreSecurityAdmin {
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnection.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,6 +22,7 @@
package com.metamatrix.common.comm.api;
+import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.platform.security.api.LogonResult;
public interface ServerConnection {
@@ -36,4 +37,6 @@
LogonResult getLogonResult();
+ boolean isSameInstance(ServerConnection conn) throws CommunicationException;
+
}
\ No newline at end of file
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,8 +22,11 @@
package com.metamatrix.common.comm.api;
+import java.net.URL;
import java.util.Properties;
+import com.metamatrix.admin.api.core.Admin;
+import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.common.comm.exception.ConnectionException;
@@ -40,4 +43,12 @@
*/
ServerConnection createConnection(Properties connectionProperties) throws CommunicationException, ConnectionException;
+
+ public Admin getAdminAPI(Properties connectionProperties) throws AdminException;
+
+ /**
+ * Shutdown the connection factory, including the DQP and all its existing connections
+ */
+ public void shutdown();
+
}
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/client/ServerAdminFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/client/ServerAdminFactory.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/client/ServerAdminFactory.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -213,14 +213,12 @@
return createAdmin(p);
}
- public ServerAdmin createAdmin(Properties p)
- throws AdminComponentException, AdminException {
+ public ServerAdmin createAdmin(Properties p) {
p = PropertiesUtils.clone(p);
p.remove(MMURL.JDBC.VDB_NAME);
p.remove(MMURL.JDBC.VDB_VERSION);
p.setProperty(MMURL.CONNECTION.AUTO_FAILOVER, Boolean.TRUE.toString());
- ServerAdmin serverAdmin = (ServerAdmin)Proxy.newProxyInstance(Thread.currentThread()
- .getContextClassLoader(), new Class[] { ServerAdmin.class }, new ReconnectingProxy(p));
+ ServerAdmin serverAdmin = (ServerAdmin)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { ServerAdmin.class }, new ReconnectingProxy(p));
return serverAdmin;
}
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -293,12 +293,15 @@
}
}
- public boolean isSameInstance(SocketServerConnection otherService) throws CommunicationException {
+ public boolean isSameInstance(ServerConnection otherService) throws CommunicationException {
+ if (!(otherService instanceof SocketServerConnection)) {
+ return false;
+ }
SocketAddress address = selectServerInstance().getRemoteAddress();
if (address == null) {
return false;
}
- return address.equals(otherService.selectServerInstance().getRemoteAddress());
+ return address.equals(((SocketServerConnection)otherService).selectServerInstance().getRemoteAddress());
}
public void selectNewServerInstance(Object service) {
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -29,24 +29,28 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.InetAddress;
+import java.net.URL;
import java.net.UnknownHostException;
+import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Timer;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.metamatrix.admin.api.core.Admin;
+import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.common.api.HostInfo;
import com.metamatrix.common.api.MMURL;
import com.metamatrix.common.comm.api.ServerConnectionFactory;
import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.common.comm.exception.ConnectionException;
+import com.metamatrix.common.comm.platform.client.ServerAdminFactory;
import com.metamatrix.common.util.NetUtils;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.core.MetaMatrixCoreException;
@@ -288,4 +292,15 @@
this.maxCachedInstances = maxCachedInstances;
}
+ @Override
+ public Admin getAdminAPI(Properties connectionProperties) throws AdminException {
+ ServerAdminFactory factory = ServerAdminFactory.getInstance();
+ return factory.createAdmin(connectionProperties);
+ }
+
+ @Override
+ public void shutdown() {
+ // only applies in the Embedded scenario.
+ }
+
}
Modified: trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -36,11 +36,24 @@
public static final String DQP_KEYSTORE = "dqp.keystore"; //$NON-NLS-1$
public static final String DQP_WORKDIR = "dqp.workdir"; //$NON-NLS-1$
public static final String DQP_LIBDIR = "dqp.lib"; //$NON-NLS-1$
+ public static final String PROCESSNAME = "processName"; //$NON-NLS-1$
+ public static final String CLUSTERNAME = "clusterName"; //$NON-NLS-1$
+
+ // socket specific
+ public static final String BIND_ADDRESS = "server.bindAddress"; //$NON-NLS-1$
+ public static final String SERVER_PORT = "server.portNumber"; //$NON-NLS-1$
+ public static final String MAX_THREADS = "server.maxSocketThreads"; //$NON-NLS-1$
+ public static final String INPUT_BUFFER_SIZE = "server.inputBufferSize"; //$NON-NLS-1$
+ public static final String OUTPUT_BUFFER_SIZE = "server.outputBufferSize"; //$NON-NLS-1$
//derived properties
public static final String DQP_IDENTITY = "dqp.identity"; //$NON-NLS-1$
public static final String DQP_TMPDIR = "mm.io.tmpdir"; //$NON-NLS-1$
public static final String DQP_WORKSPACE = "dqp.workspacedir"; //$NON-NLS-1$
+ public static final String BOOTURL = "bootURL"; //$NON-NLS-1$
+ public static final String ENABLE_SOCKETS = "sockets.enabled"; //$NON-NLS-1$
+ public static final String HOST_ADDRESS = "hostAddress"; //$NON-NLS-1$
+
public interface BufferService {
/**
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BaseDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BaseDriver.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BaseDriver.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -82,8 +82,8 @@
return driverProps.toArray(propInfo);
}
- abstract List<DriverPropertyInfo> getAdditionalPropertyInfo(String url, Properties info);
+ protected abstract List<DriverPropertyInfo> getAdditionalPropertyInfo(String url, Properties info);
- abstract void parseURL(String url, Properties info) throws SQLException;
+ protected abstract void parseURL(String url, Properties info) throws SQLException;
}
\ No newline at end of file
Deleted: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactory.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactory.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactory.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.jdbc;
-
-import java.net.URL;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Properties;
-
-/**
- * A marker interface for creating connections Embedded DQP. The interface is
- * defined so that it can be used with DQP class loading.
- */
-public interface EmbeddedConnectionFactory {
-
- public void initialize(URL bootstrapURL, Properties props) throws SQLException;
-
- /**
- * Create a Connection to the DQP. This will load a DQP instance if one is not present
- * @param properties
- * @return Connection to DQP
- * @throws SQLException
- */
- public Connection createConnection(Properties properties) throws SQLException;
-
- /**
- * Shutdown the connection factory, including the DQP and all its existing connections
- */
- public void shutdown();
-}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,7 +22,6 @@
package com.metamatrix.jdbc;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@@ -44,6 +43,10 @@
import java.util.regex.Pattern;
import com.metamatrix.common.classloader.PostDelegatingClassLoader;
+import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.api.ServerConnectionFactory;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.exception.ConnectionException;
import com.metamatrix.common.protocol.MMURLConnection;
import com.metamatrix.common.protocol.MetaMatrixURLStreamHandlerFactory;
import com.metamatrix.common.protocol.URLHelper;
@@ -140,7 +143,7 @@
// now create the connection
EmbeddedTransport transport = getDQPTransport(dqpURL, info);
- Connection conn = transport.createConnection(info);
+ Connection conn = transport.createConnection(dqpURL, info);
return conn;
}
@@ -179,7 +182,7 @@
* @param The properties object which is to be updated with properties in the URL.
* @throws SQLException if the URL is not in the expected format.
*/
- void parseURL(String url, Properties info) throws SQLException {
+ protected void parseURL(String url, Properties info) throws SQLException {
if (url == null || url.trim().length() == 0) {
String logMsg = BaseDataSource.getResourceMessage("EmbeddedDriver.URL_must_be_specified"); //$NON-NLS-1$
throw new SQLException(logMsg);
@@ -279,7 +282,7 @@
}
@Override
- List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
+ protected List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
Properties info) {
return Collections.emptyList();
}
@@ -324,9 +327,8 @@
* @since 4.3
*/
static class EmbeddedTransport {
- private EmbeddedConnectionFactory connectionFactory;
+ private ServerConnectionFactory connectionFactory;
private ClassLoader classLoader;
- private String workspaceDirectory;
private URL url;
public EmbeddedTransport(URL dqpURL, Properties info) throws SQLException {
@@ -338,13 +340,7 @@
props.putAll(info);
props = PropertiesUtils.resolveNestedProperties(props);
-
- String dqpId = getDQPIdentity();
- props.setProperty(DQPEmbeddedProperties.DQP_IDENTITY, dqpId);
- // Create a temporary workspace directory
- this.workspaceDirectory = createWorkspace(props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR), dqpId);
- props.setProperty(DQPEmbeddedProperties.DQP_WORKSPACE, this.workspaceDirectory);
-
+
// a non-delegating class loader will be created from where all third party dependent jars can be loaded
ArrayList<URL> runtimeClasspathList = new ArrayList<URL>();
String libLocation = props.getProperty(DQPEmbeddedProperties.DQP_LIBDIR, "./lib/"); //$NON-NLS-1$
@@ -380,10 +376,9 @@
Thread.currentThread().setContextClassLoader(this.classLoader);
String className = "com.metamatrix.jdbc.EmbeddedConnectionFactoryImpl"; //$NON-NLS-1$
Class<?> clazz = this.classLoader.loadClass(className);
- this.connectionFactory = (EmbeddedConnectionFactory)clazz.newInstance();
- this.connectionFactory.initialize(dqpURL, props);
+ this.connectionFactory = (ServerConnectionFactory)clazz.newInstance();
} catch (Exception e) {
- throw new EmbeddedSQLException(e);
+ throw MMSQLException.create(e);
} finally {
Thread.currentThread().setContextClassLoader(current);
}
@@ -439,7 +434,7 @@
return props;
}catch(IOException e) {
String logMsg = BaseDataSource.getResourceMessage("EmbeddedTransport.invalid_dqpproperties_path", new Object[] {dqpURL}); //$NON-NLS-1$
- throw new EmbeddedSQLException(e, logMsg);
+ throw MMSQLException.create(e, logMsg);
}finally {
if (in != null) {
try{in.close();}catch(IOException e) {}
@@ -451,15 +446,7 @@
* Shutdown the current transport
*/
void shutdown() {
- this.connectionFactory.shutdown();
-
- // remove any artifacts which are not cleaned-up
- if (this.workspaceDirectory != null) {
- File file = new File(this.workspaceDirectory);
- if (file.exists()) {
- delete(file);
- }
- }
+ this.connectionFactory.shutdown();
}
/**
@@ -468,80 +455,25 @@
* @param info
* @return Connection
*/
- Connection createConnection(Properties info) throws SQLException {
+ Connection createConnection(URL url, Properties info) throws SQLException {
ClassLoader current = null;
try {
current = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
- return connectionFactory.createConnection(info);
+ Thread.currentThread().setContextClassLoader(classLoader);
+ try {
+ info.setProperty(DQPEmbeddedProperties.BOOTURL, url.toExternalForm());
+ ServerConnection conn = connectionFactory.createConnection(info);
+ return new MMConnection(conn, info, url.toExternalForm(), connectionFactory);
+ } catch (CommunicationException e) {
+ throw MMSQLException.create(e);
+ } catch (ConnectionException e) {
+ throw MMSQLException.create(e);
+ }
} finally {
Thread.currentThread().setContextClassLoader(current);
}
}
- /**
- * Define an identifier for the DQP
- * @return a JVM level unique identifier
- */
- String getDQPIdentity() {
- synchronized (System.class) {
- String id = System.getProperty(DQPEmbeddedProperties.DQP_IDENTITY, "1"); //$NON-NLS-1$
- int identity = Integer.parseInt(id);
- System.setProperty(DQPEmbeddedProperties.DQP_IDENTITY, String.valueOf(identity + 1));
- id = String.valueOf(identity);
- return id;
- }
- }
-
- /**
- * Create the temporary workspace directory for the dqp
- * @param identity - identity of the dqp
- * @throws MMSQLException
- */
- String createWorkspace(String baseDir, String identity) throws MMSQLException {
- if (baseDir == null) {
- baseDir = System.getProperty("java.io.tmpdir")+"/teiid/"; //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- try {
- baseDir = URLHelper.buildURL(this.url, baseDir).getPath();
- } catch (MalformedURLException e) {
- throw MMSQLException.create(e);
- }
- }
- System.setProperty(DQPEmbeddedProperties.DQP_TMPDIR, baseDir + "/temp"); //$NON-NLS-1$S
-
- File f = new File(baseDir, identity);
-
- // If directory already exists then try to delete it; because we may have
- // failed to delete at end of last run (JVM holds lock on jar files)
- if (f.exists()) {
- delete(f);
- }
-
- // since we may have cleaned it up now , create the directory again
- if (!f.exists()) {
- f.mkdirs();
- }
- return f.getAbsolutePath();
- }
-
- /**
- * delete the any directory including sub-trees
- * @param file
- */
- private void delete(File file) {
- if (file.isDirectory()) {
- File[] files = file.listFiles();
- for (int i = 0; i < files.length; i++) {
- delete(files[i]);
- } // for
- }
-
- // for saftey purpose only delete the jar files
- if (file.getName().endsWith(".jar")) { //$NON-NLS-1$
- file.delete();
- }
- }
}
}
Deleted: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedSQLException.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedSQLException.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedSQLException.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.jdbc;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.sql.SQLException;
-
-
-/**
- * @since 4.3
- */
-public class EmbeddedSQLException extends SQLException {
- private Throwable parentException = null;
- private String message = null;
-
- public EmbeddedSQLException(Throwable e) {
- this.parentException = e;
- }
-
- public EmbeddedSQLException(Throwable e, String msg) {
- this.parentException = e;
- this.message = msg;
- }
-
- public EmbeddedSQLException(String msg) {
- this.message = msg;
- }
-
- /**
- * @see java.lang.Throwable#getMessage()
- * @since 4.3
- */
- public String getMessage() {
- if (message != null && parentException != null) {
- return message + " source:"+parentException.getMessage(); //$NON-NLS-1$
- }
- else if (message != null && parentException == null ){
- return message;
- }
- return parentException.getMessage();
- }
-
- /**
- * @see java.lang.Throwable#printStackTrace()
- * @since 4.3
- */
- public void printStackTrace() {
- if (parentException != null) {
- parentException.printStackTrace();
- }
- else {
- super.printStackTrace();
- }
- }
-
- /**
- * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
- * @since 4.3
- */
- public void printStackTrace(PrintStream s) {
- if (parentException != null) {
- parentException.printStackTrace(s);
- }
- else {
- super.printStackTrace(s);
- }
- }
-
- /**
- * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
- * @since 4.3
- */
- public void printStackTrace(PrintWriter s) {
- if (parentException != null) {
- parentException.printStackTrace(s);
- }
- else {
- super.printStackTrace(s);
- }
- }
-
-}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMConnection.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -57,9 +57,15 @@
import javax.transaction.xa.Xid;
+import org.teiid.jdbc.TeiidDriver;
+
+import com.metamatrix.admin.api.core.Admin;
+import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.common.api.MMURL;
import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.api.ServerConnectionFactory;
import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerConnection;
import com.metamatrix.common.util.SqlUtil;
import com.metamatrix.common.xa.MMXid;
import com.metamatrix.common.xa.XATransactionException;
@@ -81,9 +87,13 @@
* methods in the class throw SQLException.</p>
*/
-public abstract class MMConnection extends WrapperImpl implements com.metamatrix.jdbc.api.Connection {
+public class MMConnection extends WrapperImpl implements com.metamatrix.jdbc.api.Connection {
private static Logger logger = Logger.getLogger("org.teiid.jdbc"); //$NON-NLS-1$
-
+
+ // constant value giving product name
+ private final static String SERVER_NAME = "Teiid Server"; //$NON-NLS-1$
+ private final static String EMBEDDED_NAME = "Teiid Embedded"; //$NON-NLS-1$
+
// Unique request ID generator
private long requestIDGenerator;
@@ -112,6 +122,9 @@
private boolean disableLocalTransactions = false;
private ClientSideDQP dqp;
protected ServerConnection serverConn;
+
+ private Admin admin;
+ ServerConnectionFactory connFactory = null;
/**
* <p>MMConnection constructor, tring to establish connection to metamatrix with
@@ -120,10 +133,12 @@
* @param info contains properies needed to establish a MetaMatrix connection.
* @throws SQLException if the driver cannot establish connection to metamatrix.
*/
- public MMConnection(ServerConnection serverConn, Properties info, String url) {
+ public MMConnection(ServerConnection serverConn, Properties info, String url, ServerConnectionFactory connFactory) {
this.serverConn = serverConn;
this.url = url;
- this.dqp = serverConn.getService(ClientSideDQP.class);
+ this.dqp = serverConn.getService(ClientSideDQP.class);
+ this.connFactory = connFactory;
+
// set default properties if not overridden
String overrideProp = info.getProperty(ExecutionProperties.PROP_TXN_AUTO_WRAP);
if ( overrideProp == null || overrideProp.trim().length() == 0 ) {
@@ -223,7 +238,22 @@
String getUrl() {
return this.url;
}
-
+
+ /**
+ * @see com.metamatrix.jdbc.api.Connection#getAdminAPI()
+ * @since 4.3
+ */
+ public synchronized Admin getAdminAPI() throws SQLException {
+ try {
+ if (admin == null) {
+ admin = connFactory.getAdminAPI(this.propInfo);
+ }
+ } catch(AdminException e) {
+ throw MMSQLException.create(e);
+ }
+ return admin;
+ }
+
/**
* Connection identifier of this connection
* @return identifier
@@ -287,7 +317,12 @@
logger.fine(JDBCPlugin.Util.getString("MMConnection.Connection_close_success")); //$NON-NLS-1$
// set the status of the connection to closed
closed = true;
- }
+ }
+
+ if (admin != null) {
+ admin.close();
+ }
+
}
/**
@@ -507,7 +542,12 @@
* Get the database name that this connection is representing
* @return String name of the database
*/
- public abstract String getDatabaseName();
+ public String getDatabaseName() {
+ if (this.serverConn instanceof SocketServerConnection) {
+ return SERVER_NAME;
+ }
+ return EMBEDDED_NAME;
+ }
/**
* Retrieves the current holdability of ResultSet objects created using this Connection object.
@@ -908,12 +948,24 @@
} catch (SQLException e) {
logger.log(Level.WARNING, JDBCPlugin.Util.getString("MMXAConnection.rolling_back_error"), e); //$NON-NLS-1$
}
+
+ //perform load balancing
+ if (this.serverConn instanceof SocketServerConnection) {
+ ((SocketServerConnection)this.serverConn).selectNewServerInstance(this.getDQP());
+ }
}
- public abstract BaseDriver getBaseDriver();
+ public BaseDriver getBaseDriver() {
+ if (this.serverConn instanceof SocketServerConnection) {
+ return new TeiidDriver();
+ }
+ return new EmbeddedDriver();
+ }
- public abstract boolean isSameProcess(MMConnection conn) throws CommunicationException;
-
+ public boolean isSameProcess(MMConnection conn) throws CommunicationException {
+ return this.serverConn.isSameInstance(conn.serverConn);
+ }
+
//## JDBC4.0-begin ##
public void setClientInfo(Properties properties)
throws SQLClientInfoException {
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDriver.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDriver.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -137,13 +137,13 @@
return myConnection;
}
- MMServerConnection createMMConnection(String url, Properties info)
+ MMConnection createMMConnection(String url, Properties info)
throws ConnectionException, CommunicationException {
ServerConnection serverConn = SocketServerConnectionFactory.getInstance().createConnection(info);
// construct a MMConnection object.
- MMServerConnection connection = MMServerConnection.newInstance(serverConn, info, url);
+ MMConnection connection = new MMConnection(serverConn, info, url, SocketServerConnectionFactory.getInstance());
return connection;
}
@@ -157,7 +157,7 @@
* @param The properties object which is to be updated with properties in the URL.
* @throws SQLException if the URL is not in the expected format.
*/
- void parseURL(String url, Properties info) throws SQLException {
+ protected void parseURL(String url, Properties info) throws SQLException {
if(url == null) {
String msg = JDBCPlugin.Util.getString("MMDriver.urlFormat"); //$NON-NLS-1$
throw new MMSQLException(msg);
@@ -230,7 +230,7 @@
}
@Override
- List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
+ protected List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
Properties info) {
List<DriverPropertyInfo> dpis = new LinkedList<DriverPropertyInfo>();
DriverPropertyInfo dpi = new DriverPropertyInfo(MMURL.CONNECTION.SERVER_URL, info.getProperty(MMURL.CONNECTION.SERVER_URL));
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -197,11 +197,9 @@
if (childException instanceof MMSQLException) {
super.setNextException(ex);
break;
- } else {
- super.setNextException(new MMSQLException(childException, getMessage(childException, null),
- false));
- childException = childException.getNextException();
}
+ super.setNextException(new MMSQLException(childException, getMessage(childException, null),false));
+ childException = childException.getNextException();
}
}
}
@@ -210,7 +208,7 @@
* Constructor a MMSQLException object initialized with reason.
* @param reason String object which is the description of the exception.
*/
- MMSQLException(String reason) {
+ public MMSQLException(String reason) {
super(reason, SQLStates.DEFAULT);
}
Deleted: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMServerConnection.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMServerConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMServerConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,124 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.jdbc;
-
-import java.sql.SQLException;
-import java.util.Properties;
-
-import com.metamatrix.admin.api.core.Admin;
-import com.metamatrix.admin.api.server.ServerAdmin;
-import com.metamatrix.common.comm.api.ServerConnection;
-import com.metamatrix.common.comm.exception.CommunicationException;
-import com.metamatrix.common.comm.platform.client.ServerAdminFactory;
-import com.metamatrix.common.comm.platform.socket.client.SocketServerConnection;
-
-/**
- * @since 4.3
- */
-public class MMServerConnection extends MMConnection {
-
- // constant value giving product name
- private final static String SERVER_NAME = "Teiid Server"; //$NON-NLS-1$
-
- private ServerAdmin serverAdmin;
-
- /**
- * Factory Constructor
- * @param serverConn
- * @param info
- * @param url
- */
- public static MMServerConnection newInstance(ServerConnection serverConn, Properties info, String url) {
- return new MMServerConnection(serverConn, info, url);
- }
-
- /**
- * @param driver
- * @param serverConn
- * @param info
- * @param url
- * @param tracker
- * @since 4.3
- */
- public MMServerConnection(ServerConnection serverConn, Properties info, String url) {
- super(serverConn, info, url);
- }
-
- /**
- * @see com.metamatrix.jdbc.api.Connection#getAdminAPI()
- * @since 4.3
- */
- public synchronized Admin getAdminAPI() throws SQLException {
- try {
- if (serverAdmin == null) {
- ServerAdminFactory factory = ServerAdminFactory.getInstance();
- serverAdmin = factory.createAdmin(this.propInfo);
- }
- } catch(Exception e) {
- throw MMSQLException.create(e);
- }
- return serverAdmin;
- }
-
- /**
- * @see com.metamatrix.jdbc.MMConnection#close()
- * @since 4.3
- */
- public synchronized void close() throws SQLException {
- super.close();
- if (serverAdmin != null) {
- serverAdmin.close();
- }
- }
-
- /**
- * @see com.metamatrix.jdbc.MMConnection#getDatabaseName()
- */
- public String getDatabaseName() {
- return SERVER_NAME;
- }
-
- @Override
- public BaseDriver getBaseDriver() {
- return new MMDriver();
- }
-
- @Override
- public void recycleConnection() {
- super.recycleConnection();
- //perform load balancing
- if (this.serverConn instanceof SocketServerConnection) {
- ((SocketServerConnection)this.serverConn).selectNewServerInstance(this.getDQP());
- }
- }
-
- @Override
- public boolean isSameProcess(MMConnection conn) throws CommunicationException {
- if (conn instanceof MMServerConnection
- && this.serverConn instanceof SocketServerConnection
- && conn.serverConn instanceof SocketServerConnection) {
- return ((SocketServerConnection)this.serverConn).isSameInstance((SocketServerConnection)conn.serverConn);
- }
- return false;
- }
-}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -40,7 +40,8 @@
*/
public class MMJDBCURL {
private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
- private static final String JDBC_PROTOCOL = "jdbc:metamatrix:"; //$NON-NLS-1$
+ private static final String JDBC_PROTOCOL = "jdbc:teiid:"; //$NON-NLS-1$
+ private static final String OLD_JDBC_PROTOCOL = "jdbc:metamatrix:"; //$NON-NLS-1$
private static final String[] KNOWN_PROPERTIES = {
BaseDataSource.APP_NAME,
@@ -134,13 +135,22 @@
}
private void parseJDBCProtocol(String protocol) {
- if (!protocol.startsWith(JDBC_PROTOCOL)) {
- throw new IllegalArgumentException();
- }
- if (protocol.length() == JDBC_PROTOCOL.length()) {
- throw new IllegalArgumentException();
- }
- vdbName = protocol.substring(JDBC_PROTOCOL.length());
+ if (protocol.startsWith(JDBC_PROTOCOL)) {
+ if (protocol.length() == JDBC_PROTOCOL.length()) {
+ throw new IllegalArgumentException();
+ }
+ vdbName = protocol.substring(JDBC_PROTOCOL.length());
+ }
+ else if (protocol.startsWith(OLD_JDBC_PROTOCOL)) {
+ if (protocol.length() == OLD_JDBC_PROTOCOL.length()) {
+ throw new IllegalArgumentException();
+ }
+ vdbName = protocol.substring(OLD_JDBC_PROTOCOL.length());
+ }
+ else {
+ throw new IllegalArgumentException();
+ }
+
}
private void parseConnectionPart(String connectionInfo) {
Added: trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDataSource.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDataSource.java (rev 0)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDataSource.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,490 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.Connection;
+import java.util.Properties;
+
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.jdbc.BaseDataSource;
+import com.metamatrix.jdbc.JDBCPlugin;
+import com.metamatrix.jdbc.MMSQLException;
+import com.metamatrix.jdbc.util.MMJDBCURL;
+
+/**
+ * The MetaMatrix JDBC DataSource implementation class of {@link javax.sql.DataSource} and
+ * {@link javax.sql.XADataSource}.
+ * <p>
+ * The {@link javax.sql.DataSource} interface follows the JavaBean design pattern,
+ * meaning the implementation class has <i>properties</i> that are accessed with getter methods
+ * and set using setter methods, and where the getter and setter methods follow the JavaBean
+ * naming convention (e.g., <code>get</code><i>PropertyName</i><code>() : </code><i>PropertyType</i>
+ * and <code>set</code><i>PropertyName</i><code>(</code><i>PropertyType</i><code>) : void</code>).
+ * </p>
+ * The {@link javax.sql.XADataSource} interface is almost identical to the {@link javax.sql.DataSource}
+ * interface, but rather than returning {@link java.sql.Connection} instances, there are methods that
+ * return {@link javax.sql.XAConnection} instances that can be used with distributed transactions.
+ * <p>
+ * The following are the properties for this DataSource:
+ * <table cellspacing="0" cellpadding="0" border="1" width="100%">
+ * <tr><td><b>Property Name</b></td><td><b>Type</b></td><td><b>Description</b></td></tr>
+ * <tr><td>portNumber </td><td><code>int </code></td><td>The port number where a MetaMatrix Server is listening
+ * for requests.</td></tr>
+ * <tr><td>serverName </td><td><code>String</code></td><td>The hostname or IP address of the MetaMatrix Server.</td></tr>
+ * <table>
+ * </p>
+ */
+public class TeiidDataSource extends BaseDataSource {
+
+ /**
+ * The port number where a MetaMatrix Server is listening for requests.
+ * This property name is one of the standard property names defined by the JDBC 2.0 specification,
+ * and is <i>optional</i>.
+ */
+ private int portNumber;
+
+ /**
+ * The name of the host where the MetaMatrix Server is running.
+ * This property name is one of the standard property names defined by the JDBC 2.0 specification,
+ * and is <i>required</i>.
+ */
+ private String serverName;
+
+ /**
+ * Specify a set of data source credentials to pass to the connectors as defined in
+ * {@link MMURL.JDBC.CREDENTIALS}.
+ */
+ private String credentials;
+
+ /**
+ * Specify whether to make a secure (SSL, mms:) connection or a normal non-SSL mm: connection.
+ * the default is to use a non-secure connection.
+ * @since 5.0.2
+ */
+ private boolean secure = false;
+
+ /**
+ * Holds a comma delimited list of alternate MetaMatrix Server(s):Port(s) that can
+ * be used for connection fail-over.
+ * @since 5.5
+ */
+ private String alternateServers;
+
+ /**
+ * The auto failover mode for calls made to the query engine. If true query engine calls that fail will
+ * allow the connection to choose another process.
+ */
+ private String autoFailover;
+
+ private String discoveryStrategy;
+
+ /**
+ * Constructor for MMDataSource.
+ */
+ public TeiidDataSource() {
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // H E L P E R M E T H O D S
+ // --------------------------------------------------------------------------------------------
+
+ protected Properties buildProperties(final String userName, final String password) {
+ Properties props = super.buildProperties(userName, password);
+
+ props.setProperty(MMURL.CONNECTION.SERVER_URL,this.buildServerURL());
+
+ if (this.getAutoFailover() != null) {
+ props.setProperty(MMURL.CONNECTION.AUTO_FAILOVER, this.getAutoFailover());
+ }
+
+ if (this.getCredentials() != null) {
+ props.setProperty(MMURL.JDBC.CREDENTIALS, this.getCredentials());
+ }
+
+ if (this.getDiscoveryStrategy() != null) {
+ props.setProperty(MMURL.CONNECTION.DISCOVERY_STRATEGY, this.getDiscoveryStrategy());
+ }
+
+ return props;
+ }
+
+ protected String buildServerURL() {
+ if ( this.alternateServers == null ) {
+ // Format: "mm://server:port"
+ return new MMURL(this.serverName, this.portNumber, this.secure).getAppServerURL();
+ }
+
+ // Format: "mm://server1:port,server2:port,..."
+ String serverURL = ""; //$NON-NLS-1$
+
+ serverURL = "" + ( this.secure ? MMURL.SECURE_PROTOCOL : MMURL.DEFAULT_PROTOCOL ); //$NON-NLS-1$
+ serverURL += "" + this.serverName; //$NON-NLS-1$
+ if ( this.portNumber != 0 )
+ serverURL += MMURL.COLON_DELIMITER + this.portNumber;
+ if ( this.alternateServers.length() > 0 ) {
+ String[] as = this.alternateServers.split( MMURL.COMMA_DELIMITER);
+
+ for ( int i = 0; i < as.length; i++ ) {
+ String[] server = as[i].split( MMURL.COLON_DELIMITER );
+
+ if ( server.length > 0 ) {
+ serverURL += MMURL.COMMA_DELIMITER + server[0];
+ if ( server.length > 1 ) {
+ serverURL += MMURL.COLON_DELIMITER + server[1];
+ } else {
+ serverURL += MMURL.COLON_DELIMITER + this.portNumber;
+ }
+ }
+ }
+ }
+
+ return new MMURL(serverURL).getAppServerURL();
+ }
+
+ protected String buildURL() {
+ return new MMJDBCURL(this.getDatabaseName(), buildServerURL(), buildProperties(getUser(), getPassword())).getJDBCURL();
+ }
+
+ protected void validateProperties( final String userName, final String password) throws java.sql.SQLException {
+ super.validateProperties(userName, password);
+
+ String reason = reasonWhyInvalidPortNumber(this.portNumber);
+ if ( reason != null ) {
+ throw createConnectionError(reason);
+ }
+
+ reason = reasonWhyInvalidServerName(this.serverName);
+ if ( reason != null ) {
+ throw createConnectionError(reason);
+ }
+
+ reason = reasonWhyInvalidAlternateServers(this.alternateServers);
+ if ( reason != null) {
+ throw createConnectionError(reason);
+ }
+ }
+
+ private MMSQLException createConnectionError(String reason) {
+ String msg = JDBCPlugin.Util.getString("MMDataSource.Err_connecting", reason); //$NON-NLS-1$
+ return new MMSQLException(msg);
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // D A T A S O U R C E M E T H O D S
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Attempt to establish a database connection.
+ * @return a Connection to the database
+ * @throws java.sql.SQLException if a database-access error occurs
+ * @see javax.sql.DataSource#getConnection()
+ */
+ public Connection getConnection() throws java.sql.SQLException {
+ return getConnection(null,null);
+ }
+
+ /**
+ * Attempt to establish a database connection.
+ * @param userName the database user on whose behalf the Connection is being made
+ * @param password the user's password
+ * @return a Connection to the database
+ * @throws java.sql.SQLException if a database-access error occurs
+ * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
+ */
+ public Connection getConnection(String userName, String password) throws java.sql.SQLException {
+ try {
+ validateProperties(userName,password);
+ final Properties props = buildProperties(userName, password);
+ final TeiidDriver driver = new TeiidDriver();
+ return driver.createConnection(buildURL(), props);
+ } catch (MetaMatrixCoreException e) {
+ throw MMSQLException.create(e, e.getMessage());
+ }
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return buildURL().substring(16); // URL without the "jdbc:metamatrix:" at the front
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // P R O P E R T Y M E T H O D S
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Returns the port number.
+ * @return the port number
+ */
+ public int getPortNumber() {
+ return portNumber;
+ }
+
+ /**
+ * Returns the name of the MetaMatrix Server.
+ * @return the name of the MetaMatrix Server
+ */
+ public String getServerName() {
+ return serverName;
+ }
+
+ /**
+ * Returns the credentials string defining credentials to use with connectors for per-user logon.
+ * @since 4.3.2
+ */
+ public String getCredentials() {
+ return credentials;
+ }
+
+ /**
+ * Returns a flag indicating whether to create a secure connection or not.
+ * @return True if using secure mms: protocol, false for normal mm: protocol.
+ * @since 5.0.2
+ */
+ public boolean isSecure() {
+ return this.secure;
+ }
+
+ /**
+ * Returns a string containing a comma delimited list of alternate
+ * MetaMatrix Server(s).
+ *
+ * The list will be in the form of server2[:port2][,server3[:port3]]. If no
+ * alternate servers have been defined <code>null</code> is returned.
+ * @return A comma delimited list of server:port or <code>null</code> If
+ * no alternate servers are defined.
+ * @since 5.5
+ */
+ public String getAlternateServers() {
+ if ( this.alternateServers != null && this.alternateServers.length() < 1 )
+ return null;
+ return this.alternateServers;
+ }
+
+ /**
+ * Sets the portNumber.
+ * @param portNumber The portNumber to set
+ */
+ public void setPortNumber(final int portNumber) {
+ this.portNumber = portNumber;
+ }
+
+ /**
+ * Sets the serverName.
+ * @param serverName The serverName to set
+ */
+ public void setServerName(final String serverName) {
+ this.serverName = serverName;
+ }
+
+ /**
+ * Sets the credentials string defining credentials to use with connectors for per-user logon.
+ * @since 4.3.2
+ */
+ public void setCredentials(final String credentials) {
+ this.credentials = credentials;
+ }
+
+ /**
+ * Sets the secure flag to use mms: protocol instead of the default mm: protocol.
+ * @param secure True to use mms:
+ * @since 5.0.2
+ */
+ public void setSecure(final boolean secure) {
+ this.secure = secure;
+ }
+
+ /**
+ * Sets a list of alternate MetaMatrix Sserver(s) that can be used for
+ * connection fail-over.
+ *
+ * The form of the list should be server2[:port2][,server3:[port3][,...]].
+ *
+ * If ":port" is omitted, the port defined by <code>portNumber</code> is used.
+ *
+ * If <code>servers</code> is empty or <code>null</code>, the value of
+ * <code>alternateServers</code> is cleared.
+ * @param servers A comma delimited list of alternate MetaMatrix
+ * Server(s):Port(s) to use for connection fail-over. If blank or
+ * <code>null</code>, the list is cleared.
+ * @since 5.5
+ */
+ public void setAlternateServers(final String servers) {
+ this.alternateServers = servers;
+ if ( this.alternateServers != null && this.alternateServers.length() < 1 )
+ this.alternateServers = null;
+ }
+
+
+ // --------------------------------------------------------------------------------------------
+ // V A L I D A T I O N M E T H O D S
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Return the reason why the supplied port number may be invalid, or null
+ * if it is considered valid.
+ * @param portNumber a possible value for the property
+ * @return the reason why the property is invalid, or null if it is considered valid
+ * @see #setPortNumber(int)
+ */
+ public static String reasonWhyInvalidPortNumber( final int portNumber) {
+ if ( portNumber == 0 ) {
+ return null; // default is always fine
+ }
+ if ( portNumber < 1 ) {
+ return JDBCPlugin.Util.getString("MMDataSource.Port_number_must_be_positive"); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * Return the reason why the supplied server name may be invalid, or null
+ * if it is considered valid.
+ * @param serverName a possible value for the property
+ * @return the reason why the property is invalid, or null if it is considered valid
+ * @see #setServerName(String)
+ * */
+ public static String reasonWhyInvalidServerName( final String serverName ) {
+ if ( serverName == null || serverName.trim().length() == 0 ) {
+ return JDBCPlugin.Util.getString("MMDataSource.Server_name_required"); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * The reason why "socketsPerVM" is invalid.
+ * @param value of "socketsPerVM" property
+ * @return reason
+ */
+ public static String reasonWhyInvalidSocketsPerVM(final String socketsPerVM) {
+ if (socketsPerVM != null) {
+ int value = -1;
+ try {
+ value = Integer.parseInt(socketsPerVM);
+ } catch (Exception e) {
+ }
+
+ if (value <= 0) {
+ return JDBCPlugin.Util.getString("MMDataSource.Sockets_per_vm_invalid"); //$NON-NLS-1$
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * The reason why "stickyConnections" is invalid.
+ * @param value of "stickyConnections" property
+ * @return reason
+ */
+ public static String reasonWhyInvalidStickyConnections(final String stickyConnections) {
+ if (stickyConnections != null) {
+ if ((! stickyConnections.equalsIgnoreCase("true")) && //$NON-NLS-1$
+ (! stickyConnections.equalsIgnoreCase("false"))) { //$NON-NLS-1$
+ return JDBCPlugin.Util.getString("MMDataSource.Sticky_connections_invalid"); //$NON-NLS-1$
+ }
+ }
+ return null;
+ }
+
+ /**
+ * The reason why "alternateServers" is invalid.
+ * @param value of "alternateServers" property
+ * @return reason
+ */
+ public static String reasonWhyInvalidAlternateServers(final String alternateServers) {
+ if ( alternateServers == null || alternateServers.trim().length() < 1 )
+ return null;
+
+ String[] as = alternateServers.split( MMURL.COMMA_DELIMITER);
+ String sReason = null;
+ String reason = ""; //$NON-NLS-1$
+ int reasonCount = 0;
+ final String newline = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ for ( int i = 0; i < as.length; i++ ) {
+ String[] server = as[i].split( MMURL.COLON_DELIMITER );
+
+ if ( server.length < 1 || server.length > 2 ) {
+ // ie "server:31000:an invalid value"
+ // ie "server,server:31000"
+ return JDBCPlugin.Util.getString("MMDataSource.Alternate_Servers_format"); //$NON-NLS-1$
+ }
+
+ // check the server name portion
+ sReason = reasonWhyInvalidServerName(server[0] );
+ if ( sReason != null ) {
+ reason += (reason.length() > 0 ? newline : "" ) + sReason; //$NON-NLS-1$
+ reasonCount++;
+ sReason = null;
+ }
+
+ if ( server.length > 1 ) {
+ // check the port portion
+ int port = 0;
+ // parse the int from the string
+ try { port = Integer.parseInt(server[1]); }
+ catch ( NumberFormatException e ) {
+ // ie "server:invalid_port"
+ reason += (reason.length() > 0 ? newline : "" ) //$NON-NLS-1$
+ + JDBCPlugin.Util.getString("MMDataSource.serverPort_must_be_a_number"); //$NON-NLS-1$
+ reasonCount++;
+ }
+ sReason = reasonWhyInvalidPortNumber(port);
+ if ( sReason != null ) {
+ reason += (reason.length() > 0 ? newline : "" ) + sReason; //$NON-NLS-1$
+ reasonCount++;
+ sReason = null;
+ }
+ }
+ }
+ if ( reasonCount < 1 ) return null;
+ return JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", String.valueOf(reasonCount), reason); //$NON-NLS-1$
+ }
+
+ /**
+ * @return Returns the transparentFailover.
+ */
+ public String getAutoFailover() {
+ return this.autoFailover;
+ }
+
+ /**
+ * @param transparentFailover The transparentFailover to set.
+ */
+ public void setAutoFailover(String autoFailover) {
+ this.autoFailover = autoFailover;
+ }
+
+ public String getDiscoveryStrategy() {
+ return discoveryStrategy;
+ }
+
+ public void setDiscoveryStrategy(String discoveryStrategy) {
+ this.discoveryStrategy = discoveryStrategy;
+ }
+
+}
+
Property changes on: trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDataSource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java (rev 0)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.exception.ConnectionException;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerConnectionFactory;
+import com.metamatrix.common.util.ApplicationInfo;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.jdbc.BaseDataSource;
+import com.metamatrix.jdbc.BaseDriver;
+import com.metamatrix.jdbc.JDBCPlugin;
+import com.metamatrix.jdbc.MMConnection;
+import com.metamatrix.jdbc.MMSQLException;
+import com.metamatrix.jdbc.api.ConnectionProperties;
+import com.metamatrix.jdbc.util.MMJDBCURL;
+
+/**
+ * <p> The java.sql.DriverManager class uses this class to connect to MetaMatrix.
+ * The Driver Manager maintains a pool of TeiidDriver objects, which it could use
+ * to connect to MetaMatrix. The TeiidDriver class has a static initializer, which
+ * is used to instantiate and register itsef with java.sql.DriverManager. The
+ * DriverManager's <code>getConnection</code> method calls <code>connect</code>
+ * method on available registered drivers. The first driver to recognise the given
+ * url is used to obtain a connection.</p>
+ */
+
+public final class TeiidDriver extends BaseDriver {
+ private static Logger logger = Logger.getLogger("org.teiid.jdbc"); //$NON-NLS-1$
+
+ static final String DRIVER_NAME = "Teiid JDBC Driver"; //$NON-NLS-1$
+
+ /**
+ * Suports JDBC URLS of format
+ * - jdbc:teiid:BQT@mm://localhost:####;version=1
+ * - jdbc:teiid:BQT@mms://localhost:####;version=1
+ * - jdbc:teiid:BQT@mm(s)://host1:####,host2:####,host3:####;version=1
+ */
+
+ // This host/port pattern allows just a . or a - to be in the host part.
+ static final String HOST_PORT_PATTERN = "[\\p{Alnum}\\.\\-]+:\\d+"; //$NON-NLS-1$
+ static final String URL_PATTERN = "jdbc:(metamatrix|teiid):(\\w+)@((mm[s]?://"+HOST_PORT_PATTERN+"(,"+HOST_PORT_PATTERN+")*)[;]?){1}((.*)*)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ static Pattern urlPattern = Pattern.compile(URL_PATTERN);
+
+ private static TeiidDriver INSTANCE = new TeiidDriver();
+
+ // Static initializer
+ static {
+ try {
+ DriverManager.registerDriver(INSTANCE);
+ } catch(SQLException e) {
+ // Logging
+ String logMsg = JDBCPlugin.Util.getString("MMDriver.Err_registering", e.getMessage()); //$NON-NLS-1$
+ logger.log(Level.SEVERE, logMsg);
+ }
+ }
+
+ public static TeiidDriver getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Should be a singleton and only constructed in {@link #getInstance}.
+ */
+ public TeiidDriver() {
+ // this is not singleton, if you want singleton make this private.
+ }
+
+ /**
+ * This method tries to make a metamatrix connection to the given URL. This class
+ * will return a null if this is not the right driver to connect to the given URL.
+ * @param The URL used to establish a connection.
+ * @return Connection object created
+ * @throws SQLException if it is unable to establish a connection to the MetaMatrix server.
+ */
+ public Connection connect(String url, Properties info) throws SQLException {
+
+ MMConnection myConnection = null;
+ // create a properties obj if it is null
+ if(info == null) {
+ info = new Properties();
+ } else {
+ info = PropertiesUtils.clone(info);
+ }
+
+ // The url provided is in the correct format.
+ if (!acceptsURL(url)) {
+ return null;
+ }
+
+ try {
+ // parse the URL to add it's properties to properties object
+ parseURL(url, info);
+
+ myConnection = createConnection(url, info);
+ } catch (MetaMatrixCoreException e) {
+ logger.log(Level.SEVERE, "Could not create connection", e); //$NON-NLS-1$
+ throw MMSQLException.create(e, e.getMessage());
+ }
+
+ // logging
+ String logMsg = JDBCPlugin.Util.getString("JDBCDriver.Connection_sucess"); //$NON-NLS-1$
+ logger.fine(logMsg);
+
+ return myConnection;
+ }
+
+ MMConnection createConnection(String url, Properties info)
+ throws ConnectionException, CommunicationException {
+
+ ServerConnection serverConn = SocketServerConnectionFactory.getInstance().createConnection(info);
+
+ // construct a MMConnection object.
+ MMConnection connection = new MMConnection(serverConn, info, url, SocketServerConnectionFactory.getInstance());
+ return connection;
+ }
+
+ /**
+ * This method parses the URL and adds properties to the the properties object.
+ * These include required and any optional properties specified in the URL.
+ * Expected URL format -- jdbc:metamatrix:local:VDB@server:port;version=1;user=logon;
+ * password=pw;logFile=<logFile.log>;
+ * logLevel=<logLevel>;txnAutoWrap=<?>;credentials=mycredentials
+ * @param The URL needed to be parsed.
+ * @param The properties object which is to be updated with properties in the URL.
+ * @throws SQLException if the URL is not in the expected format.
+ */
+ protected void parseURL(String url, Properties info) throws SQLException {
+ if(url == null) {
+ String msg = JDBCPlugin.Util.getString("MMDriver.urlFormat"); //$NON-NLS-1$
+ throw new MMSQLException(msg);
+ }
+ try {
+ MMJDBCURL jdbcURL = new MMJDBCURL(url);
+ info.setProperty(BaseDataSource.VDB_NAME, jdbcURL.getVDBName());
+ info.setProperty(MMURL.CONNECTION.SERVER_URL, jdbcURL.getConnectionURL());
+ Properties optionalParams = jdbcURL.getProperties();
+ MMJDBCURL.normalizeProperties(info);
+ Enumeration keys = optionalParams.keys();
+ while (keys.hasMoreElements()) {
+ String propName = (String)keys.nextElement();
+ // Don't let the URL properties override the passed-in Properties object.
+ if (!info.containsKey(propName)) {
+ info.setProperty(propName, optionalParams.getProperty(propName));
+ }
+ }
+ // add the property only if it is new because they could have
+ // already been specified either through url or otherwise.
+ if(!info.containsKey(BaseDataSource.VDB_VERSION) && jdbcURL.getVDBVersion() != null) {
+ info.setProperty(BaseDataSource.VDB_VERSION, jdbcURL.getVDBVersion());
+ }
+ if(!info.containsKey(BaseDataSource.APP_NAME)) {
+ info.setProperty(BaseDataSource.APP_NAME, BaseDataSource.DEFAULT_APP_NAME);
+ }
+
+ } catch(IllegalArgumentException iae) {
+ throw new MMSQLException(JDBCPlugin.Util.getString("MMDriver.urlFormat")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns true if the driver thinks that it can open a connection to the given URL.
+ * Typically drivers will return true if they understand the subprotocol specified
+ * in the URL and false if they don't.
+ * Expected URL format is
+ * jdbc:metamatrix:subprotocol:VDB@server:port;version=1;logFile=<logFile.log>;logLevel=<logLevel>;txnAutoWrap=<?>
+ * @param The URL used to establish a connection.
+ * @return A boolean value indicating whether the driver understands the subprotocol.
+ * @throws SQLException, should never occur
+ */
+ public boolean acceptsURL(String url) throws SQLException {
+ Matcher m = urlPattern.matcher(url);
+ return m.matches();
+ }
+
+ /**
+ * Get's the driver's major version number. Initially this should be 1.
+ * @return major version number of the driver.
+ */
+ public int getMajorVersion() {
+ return ApplicationInfo.getInstance().getMajorReleaseVersion();
+ }
+
+ /**
+ * Get's the driver's minor version number. Initially this should be 0.
+ * @return major version number of the driver.
+ */
+ public int getMinorVersion() {
+ return ApplicationInfo.getInstance().getMinorReleaseVersion();
+ }
+
+ /**
+ * @see com.metamatrix.jdbc.BaseDriver#getDriverName()
+ * @since 4.3
+ */
+ public String getDriverName() {
+ return DRIVER_NAME;
+ }
+
+ @Override
+ protected List<DriverPropertyInfo> getAdditionalPropertyInfo(String url,
+ Properties info) {
+ List<DriverPropertyInfo> dpis = new LinkedList<DriverPropertyInfo>();
+ DriverPropertyInfo dpi = new DriverPropertyInfo(MMURL.CONNECTION.SERVER_URL, info.getProperty(MMURL.CONNECTION.SERVER_URL));
+ dpi.required = true;
+ dpis.add(dpi);
+ dpis.add(new DriverPropertyInfo(BaseDataSource.USER_NAME, info.getProperty(BaseDataSource.USER_NAME)));
+ dpis.add(new DriverPropertyInfo(BaseDataSource.PASSWORD, info.getProperty(BaseDataSource.PASSWORD)));
+ dpis.add(new DriverPropertyInfo(ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD, info.getProperty(BaseDataSource.PASSWORD)));
+ return dpis;
+ }
+
+}
+
+
Property changes on: trunk/client-jdbc/src/main/java/org/teiid/jdbc/TeiidDriver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMConnection.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -31,6 +31,7 @@
import junit.framework.TestCase;
import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.api.ServerConnectionFactory;
import com.metamatrix.dqp.client.ClientSideDQP;
import com.metamatrix.platform.security.api.LogonResult;
import com.metamatrix.platform.security.api.MetaMatrixSessionID;
@@ -48,7 +49,7 @@
super(name);
}
- public static MMServerConnection getMMConnection() {
+ public static MMConnection getMMConnection() {
ServerConnection mock = mock(ServerConnection.class);
stub(mock.getService(ClientSideDQP.class)).toReturn(mock(ClientSideDQP.class));
Properties props = new Properties();
@@ -59,7 +60,7 @@
productInfo.setProperty(ProductInfoConstants.VIRTUAL_DB, STD_DATABASE_NAME);
productInfo.setProperty(ProductInfoConstants.VDB_VERSION, STD_DATABASE_VERSION);
stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(new MetaMatrixSessionID(1), "metamatrixadmin"), productInfo, "fake")); //$NON-NLS-1$
- return new MMServerConnection(mock, props, serverUrl);
+ return new MMConnection(mock, props, serverUrl, mock(ServerConnectionFactory.class));
}
public void testGetMetaData() throws Exception {
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMDataSource.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMDataSource.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMDataSource.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -515,7 +515,7 @@
final String partialMode = "true"; //$NON-NLS-1$
final boolean secure = false;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,null,transactionAutoWrap, partialMode, 500, false, secure,
- "jdbc:metamatrix:vdbName@mm://hostname:7001;fetchSize=500;ApplicationName=JDBC;serverURL=mm://hostname:7001;VirtualDatabaseVersion=1.2.3;partialResultsMode=true;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mm://hostname:7001;fetchSize=500;ApplicationName=JDBC;serverURL=mm://hostname:7001;VirtualDatabaseVersion=1.2.3;partialResultsMode=true;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
}
public void testBuildingURL2() {
@@ -527,7 +527,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = false;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,null,transactionAutoWrap, partialMode, -1, false, secure,
- "jdbc:metamatrix:vdbName@mm://hostname:7001;ApplicationName=JDBC;serverURL=mm://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mm://hostname:7001;ApplicationName=JDBC;serverURL=mm://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName"); //$NON-NLS-1$
}
public void testBuildURL3() {
@@ -539,7 +539,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = false;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,null,transactionAutoWrap, partialMode, -1, true, secure,
- "jdbc:metamatrix:vdbName@mm://hostname:7001;ApplicationName=JDBC;serverURL=mm://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mm://hostname:7001;ApplicationName=JDBC;serverURL=mm://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
}
// Test secure protocol
@@ -552,7 +552,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = true;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,null,transactionAutoWrap, partialMode, -1, true, secure,
- "jdbc:metamatrix:vdbName@mms://hostname:7001;ApplicationName=JDBC;serverURL=mms://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mms://hostname:7001;ApplicationName=JDBC;serverURL=mms://hostname:7001;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
}
/*
@@ -570,7 +570,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = false;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,alternateServers,transactionAutoWrap, partialMode, -1, true, secure,
- "jdbc:metamatrix:vdbName@mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
}
/*
@@ -588,7 +588,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = true;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,alternateServers,transactionAutoWrap, partialMode, -1, true, secure,
- "jdbc:metamatrix:vdbName@mms://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mms://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mms://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mms://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
}
/*
@@ -607,7 +607,7 @@
final String partialMode = "false"; //$NON-NLS-1$
final boolean secure = false;
helpTestBuildingURL(vdbName,vdbVersion,serverName,portNumber,alternateServers,transactionAutoWrap, partialMode, -1, true, secure,
- "jdbc:metamatrix:vdbName@mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
+ "jdbc:teiid:vdbName@mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;ApplicationName=JDBC;serverURL=mm://hostName:7001,hostName:7002,hostName2:7001,hostName2:7002;txnAutoWrap=PESSIMISTIC;partialResultsMode=false;VirtualDatabaseName=vdbName;sqlOptions=SHOWPLAN"); //$NON-NLS-1$
}
public void testBuildURL_AdditionalProperties() {
@@ -616,7 +616,7 @@
ds.setServerName("hostName"); //$NON-NLS-1$
ds.setDatabaseName("vdbName"); //$NON-NLS-1$
ds.setPortNumber(1);
- assertEquals("jdbc:metamatrix:vdbName@mm://hostname:1;fetchSize=2000;ApplicationName=JDBC;serverURL=mm://hostname:1;a=b;VirtualDatabaseName=vdbName;foo=bar", ds.buildURL()); //$NON-NLS-1$
+ assertEquals("jdbc:teiid:vdbName@mm://hostname:1;fetchSize=2000;ApplicationName=JDBC;serverURL=mm://hostname:1;a=b;VirtualDatabaseName=vdbName;foo=bar", ds.buildURL()); //$NON-NLS-1$
}
public void testInvalidDataSource() {
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/util/TestMMJDBCURL.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/util/TestMMJDBCURL.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/util/TestMMJDBCURL.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -54,14 +54,14 @@
String URL = "jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1;configFile=testdata/bqt/dqp_stmt_e2e.xmi;disableLocalTxn=true;autoFailover=false"; //$NON-NLS-1$
Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1");
- expectedProperties.setProperty("user", "xyz");
- expectedProperties.setProperty("password", "***");
- expectedProperties.setProperty("logLevel", "1");
- expectedProperties.setProperty("configFile", "testdata/bqt/dqp_stmt_e2e.xmi");
- expectedProperties.setProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS, "true");
- expectedProperties.setProperty(MMURL.CONNECTION.AUTO_FAILOVER, "false");
- MMJDBCURL url = new MMJDBCURL(URL); //$NON-NLS-1$
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("password", "***"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("logLevel", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("configFile", "testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS, "true"); //$NON-NLS-1$
+ expectedProperties.setProperty(MMURL.CONNECTION.AUTO_FAILOVER, "false"); //$NON-NLS-1$
+ MMJDBCURL url = new MMJDBCURL(URL);
assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
assertEquals("mm://localhost:12345", url.getConnectionURL()); //$NON-NLS-1$
assertEquals(expectedProperties, url.getProperties());
@@ -224,14 +224,14 @@
public void testConstructor() {
MMJDBCURL url = new MMJDBCURL("myVDB", "mm://myhost:12345",null); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("jdbc:metamatrix:myVDB@mm://myhost:12345", url.getJDBCURL()); //$NON-NLS-1$
+ assertEquals("jdbc:teiid:myVDB@mm://myhost:12345", url.getJDBCURL()); //$NON-NLS-1$
Properties props = new Properties();
props.setProperty(BaseDataSource.USER_NAME, "myuser"); //$NON-NLS-1$
props.setProperty(BaseDataSource.PASSWORD, "mypassword"); //$NON-NLS-1$
props.put("ClieNTtOKeN", new Integer(1)); //$NON-NLS-1$
url = new MMJDBCURL("myVDB", "mm://myhost:12345", props); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("jdbc:metamatrix:myVDB@mm://myhost:12345;user=myuser;password=mypassword", url.getJDBCURL()); //$NON-NLS-1$
+ assertEquals("jdbc:teiid:myVDB@mm://myhost:12345;user=myuser;password=mypassword", url.getJDBCURL()); //$NON-NLS-1$
}
public void testConstructor_Exception() {
@@ -291,24 +291,6 @@
assertEquals(password, p.getProperty("password")); //$NON-NLS-1$
}
- public void testDriverManagerException() {
- //register the drivers -- MMDriver first to ensure it is not throwing an exception
- new MMDriver();
- new EmbeddedDriver();
-
- try {
- DriverManager.getConnection("jdbc:metamatrix:QT_Ora9DS@somefile"); //$NON-NLS-1$
- } catch (SQLException e) {
- assertEquals("This Path: mmfile:somefile used to locate mm.properties is invalid. Please check your file system and correct your JDBC URL. source:somefile", e.getMessage()); //$NON-NLS-1$
- }
-
- try {
- DriverManager.getConnection("jdbc:foo:QT_Ora9DS@mm://host:30000"); //$NON-NLS-1$
- } catch (SQLException e) {
- assertTrue(e.getMessage().startsWith("No suitable driver")); //$NON-NLS-1$
- }
-
- }
public void testGetServerURL_NoProperties() {
String result = new MMJDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=mm").getConnectionURL(); //$NON-NLS-1$
Added: trunk/common-core/src/main/java/com/metamatrix/common/util/JMXUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/JMXUtil.java (rev 0)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/JMXUtil.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package com.metamatrix.common.util;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import com.metamatrix.core.MetaMatrixCoreException;
+
+public class JMXUtil {
+ public enum MBeanType {SERVICE, SERVER, UTIL, ADMINAPI};
+
+ String processName;
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+ public JMXUtil(String processName) {
+ this.processName = processName;
+ }
+
+ public ObjectName buildName(MBeanType type, String name) throws FailedToRegisterException {
+ try {
+ return new ObjectName("Teiid["+processName+"]:type="+type+",name="+name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } catch (MalformedObjectNameException e) {
+ throw new FailedToRegisterException(e);
+ }
+ }
+
+ public void register(MBeanType type, String name, Object anObj) throws FailedToRegisterException {
+ try {
+ mbs.registerMBean(anObj, buildName(type, name));
+ } catch (InstanceAlreadyExistsException e) {
+ throw new FailedToRegisterException(e);
+ } catch (MBeanRegistrationException e) {
+ throw new FailedToRegisterException(e);
+ } catch (NotCompliantMBeanException e) {
+ throw new FailedToRegisterException(e);
+ }
+ }
+
+ public void unregister(MBeanType type, String name) throws FailedToRegisterException {
+ try {
+ mbs.unregisterMBean(buildName(type, name));
+ } catch (InstanceNotFoundException e) {
+ throw new FailedToRegisterException(e);
+ } catch (MBeanRegistrationException e) {
+ throw new FailedToRegisterException(e);
+ }
+ }
+
+ public static class FailedToRegisterException extends MetaMatrixCoreException{
+ public FailedToRegisterException(Throwable e) {
+ super(e);
+ }
+ }
+}
Property changes on: trunk/common-core/src/main/java/com/metamatrix/common/util/JMXUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -129,9 +129,12 @@
Enumeration propNameEnum = props.propertyNames();
while ( propNameEnum.hasMoreElements() ) {
String name = (String) propNameEnum.nextElement();
- if ( name.startsWith(searchStr) || addAll ) {
- results.put(name, props.get(name));
+ if ( name.startsWith(searchStr)) {
+ results.put(name.substring(searchStr.length()), props.get(name));
}
+ else if (addAll) {
+ results.put(name, props.get(name));
+ }
}
return results;
@@ -444,12 +447,11 @@
}
}
- public static Properties loadFromURL(String url) throws MalformedURLException, IOException {
+ public static Properties loadFromURL(URL url) throws MalformedURLException, IOException {
Properties result = new Properties();
InputStream is = null;
try {
- URL file = URLHelper.buildURL(url);
- is = file.openStream();
+ is = url.openStream();
result.load(is);
} finally {
if (is != null) {
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,396 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config;
-
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Collection;
-import java.util.Properties;
-
-import com.metamatrix.common.CommonPlugin;
-import com.metamatrix.common.config.api.ComponentType;
-import com.metamatrix.common.config.api.ComponentTypeID;
-import com.metamatrix.common.config.api.Configuration;
-import com.metamatrix.common.config.api.ConfigurationID;
-import com.metamatrix.common.config.api.ConfigurationModelContainer;
-import com.metamatrix.common.config.api.Host;
-import com.metamatrix.common.config.api.HostID;
-import com.metamatrix.common.config.api.ResourceModel;
-import com.metamatrix.common.config.api.SharedResource;
-import com.metamatrix.common.config.api.VMComponentDefn;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.common.config.model.BasicHost;
-import com.metamatrix.common.config.reader.CurrentConfigurationReader;
-import com.metamatrix.common.config.reader.PropertiesConfigurationReader;
-import com.metamatrix.common.properties.UnmodifiableProperties;
-import com.metamatrix.common.util.ApplicationInfo;
-import com.metamatrix.common.util.ErrorMessageKeys;
-import com.metamatrix.common.util.NetUtils;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ReflectionHelper;
-
-/**
- * <p>
- * This class represents a single and universal framework for accessing
- * the current configuration for an application or server VM. The current
- * configuration contains the specification of runtime properties and
- * component deployment information. Depending upon the bootstrap information,
- * this framework may access the configuration information from a central
- * repository or simply from a local file.
- * </p>
- * <p>
- * This framework can be configured to periodically refresh the cached
- * configuation information, and a separate thread is used to do this in
- * the background. As such, the static <code>shutdown()</code> method
- * should be called by applications when exiting. This method will block until
- * this framework has successfully shutdown and cleaned up all resources,
- * and will return gracefully if the method were already called.
- * Note, however, that any call to this framework to obtain configuration
- * information will restart the framework, requiring another eventual
- * shutdown.
- * </p>
- */
-public final class CurrentConfiguration {
- /*
- * This property enables the overriding of the default {@link BOOTSTRAP_FILE_NAME}
- */
- public static final String BOOTSTRAP_FILE_PROPERTY_OVERRIDE = "teiid.bootstrap.file"; //$NON-NLS-1$
-
- public static final String BOOTSTRAP_FILE_NAME = "teiid.properties"; //$NON-NLS-1$
- public static final String CONFIGURATION_READER_CLASS_PROPERTY_NAME = "metamatrix.config.reader"; //$NON-NLS-1$
- public static final String CLUSTER_NAME = "cluster.name"; //$NON-NLS-1$
- public static final String CONFIGURATION_NAME= "configuration.name"; //$NON-NLS-1$
- public static final String CLUSTER_MEMBERS = "cluster.unicast.members"; //$NON-NLS-1$
-
- private CurrentConfigurationReader reader;
- private Properties bootstrapProperties;
- private Properties modifyableBootstrapProperties;
- private Properties systemBootstrapProperties;
- private String bindAddress;
- private InetAddress hostAddress;
- private String configurationName;
- private String processName;
-
- private static CurrentConfiguration INSTANCE = new CurrentConfiguration();
-
- public static CurrentConfiguration getInstance() {
- return INSTANCE;
- }
-
- /**
- * Private constructor that prevents instantiation.
- */
- private CurrentConfiguration() {
- setHostProperties(null);
- }
-
- private void setHostProperties(String bind) {
- Host host = getDefaultHost();
- this.configurationName = host.getFullName();
- String hostName = host.getHostAddress();
- if (bind == null) {
- bind = host.getBindAddress();
- }
-
- boolean bindAddressDefined = (bind != null && bind.length() > 0);
- boolean hostNameDefined = (hostName != null && hostName.length() > 0);
-
- try {
- if (hostNameDefined) {
- this.hostAddress = NetUtils.resolveHostByName(hostName);
- }
-
- if (bindAddressDefined) {
- this.bindAddress = bind;
-
- if (!hostNameDefined) {
- this.hostAddress = InetAddress.getByName(bindAddress);
- }
- }
- else {
- if (!hostNameDefined) {
- this.hostAddress = NetUtils.getInstance().getInetAddress();
- }
- this.bindAddress = this.hostAddress.getHostAddress();
- }
- } catch (UnknownHostException e) {
- throw new RuntimeException(e);
- }
-
- // these properties will be used to identify the server in TCP based cluster setup.
- String unicastMembers = bootstrapProperties.getProperty(CLUSTER_MEMBERS);
- if (unicastMembers == null) {
- unicastMembers = this.configurationName+"|"+this.hostAddress.getCanonicalHostName(); //$NON-NLS-1$
- }
- else {
- unicastMembers = unicastMembers+","+this.configurationName+"|"+this.hostAddress.getCanonicalHostName(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- modifyableBootstrapProperties.setProperty(CLUSTER_MEMBERS, unicastMembers);
- }
-
- public boolean isAvailable() {
- return this.reader != null;
- }
-
- /**
- * Return the stringified representation of this application information object.
- * @return the string form of this object; never null
- */
- public String getHostInfo() {
- StringBuffer sb = new StringBuffer("Host Information"); //$NON-NLS-1$
- sb.append('\n');
- sb.append(" VM Name: " + processName ); //$NON-NLS-1$
- sb.append('\n');
- sb.append(" Hostname: " + hostAddress.getCanonicalHostName() ); //$NON-NLS-1$
- sb.append('\n');
- sb.append(" Version: ").append(ApplicationInfo.getInstance().getReleaseNumber()); //$NON-NLS-1$
- sb.append('\n');
- sb.append(" Build Date: ").append(ApplicationInfo.getInstance().getBuildDate()); //$NON-NLS-1$
- return sb.toString();
- }
-
- public void setProcessName(String name) {
- VMComponentDefn deployedVM;
- try {
- deployedVM = getConfiguration().getVMForHost(getDefaultHost().getName(), name);
- } catch (ConfigurationException e) {
- throw new MetaMatrixRuntimeException(e);
- }
-
- if (deployedVM == null) {
- throw new MetaMatrixRuntimeException(CommonPlugin.Util.getString("CurrentConfiguration.unknown_process", name)); //$NON-NLS-1$
- }
- this.processName = name;
- setHostProperties(deployedVM.getBindAddress());
- }
-
- public String getBindAddress() {
- return bindAddress;
- }
-
- public InetAddress getHostAddress() {
- return hostAddress;
- }
-
- public String getConfigurationName() {
- return configurationName;
- }
-
- public String getProcessName() {
- return processName;
- }
-
- public String getClusterName() throws ConfigurationException {
- Properties props = getResourceProperties(ResourceNames.JGROUPS);
- return props.getProperty(CLUSTER_NAME, "Teiid-Cluster"); //$NON-NLS-1$
- }
-
- /**
- * Get all of the configuration properties. The properties
- * that are returned have default properties that are the bootstrap properties.
- * @return the immutable properties; never null
- * @throws ConfigurationException if the current configuration and/or
- * bootstrap properties could not be obtained
- */
- public Properties getProperties() {
- try {
- ConfigurationModelContainer cmc = getReader().getConfigurationModel();
- ComponentTypeID id = cmc.getConfiguration().getComponentTypeID();
- Properties result = new Properties(getBootStrapProperties());
- PropertiesUtils.putAll(result, cmc.getDefaultPropertyValues(id));
- PropertiesUtils.putAll(result, cmc.getConfiguration().getProperties());
- return new UnmodifiableProperties(result);
- } catch (ConfigurationException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
-
- /**
- * Get the connection properties for the specified resource. The resourse name
- * is dependent on the type of resource. For services, excluding connectors,
- * the resource name will be the component type name {@link com.metamatrix.common.config.api.ComponentType}.
- * For other types, they will generally have a predefined static variable
- * called RESOURCE_NAME that will be used to ask for its properties.
- * @param resourceName is the name of the resource to obtain properties for.
- * @return the immutable properties; never null
- * @throws ConfigurationException if the current configuration and/or
- * bootstrap properties could not be obtained
- */
- public Properties getResourceProperties(String resourceName) throws ConfigurationException {
- Properties result;
-
- SharedResource sr = getReader().getConfigurationModel().getResource(resourceName);
-
- Properties props;
- if (sr != null) {
- props = ResourceModel.getDefaultProperties(resourceName);
- props.putAll(sr.getProperties());
- } else {
- props = new Properties();
-
- }
-
- // allow the system properties to override
- PropertiesUtils.setOverrideProperies(props, getSystemBootStrapProperties());
-
- result = new UnmodifiableProperties(props);
-
- return result;
- }
-
- /**
- * Get the current configuration that is to be used for deployment.
- * @return the Configuration used for deployment
- * @throws ConfigurationException if the current configuration could not be obtained
- */
- public Configuration getConfiguration() throws ConfigurationException {
- Configuration config = getReader().getConfigurationModel().getConfiguration();
- if ( config == null ) {
- throw new ConfigurationException(ErrorMessageKeys.CONFIG_ERR_0021, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0021));
- }
- return config;
- }
-
-
- /**
- * Get the current configuration that is to be used for deployment.
- * @return the Configuration used for deployment
- * @throws ConfigurationException if the current configuration could not be obtained
- */
- public ConfigurationModelContainer getConfigurationModel() throws ConfigurationException {
- ConfigurationModelContainer config = null;
- try {
- config = getReader().getConfigurationModel();
- } catch (UnsupportedOperationException e) {
- }
-
- if (config == null) {
- throw new ConfigurationException(ErrorMessageKeys.CONFIG_ERR_0022,
- CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0022));
- }
-
- return config;
- }
-
- /**
- * Returns a <code>Collection</code> of type <code>ComponentType</code> that represent
- * all the ComponentTypes defined.
- * @param includeDeprecated true if class names that have been deprecated should be
- * included in the returned list, or false if only non-deprecated constants should be returned.
- * @return List of type <code>ComponentType</code>
- * @throws ConfigurationException if an error occurred within or during communication with the Configuration Service.
- * @see com.metamatrix.common.api.ComponentType
- */
- public Collection<ComponentType> getComponentTypes(boolean includeDeprecated) throws ConfigurationException {
- return getReader().getConfigurationModel().getComponentTypes().values();
- }
-
-
- /**
- * Returns the Host based on the current running machine.
- * @return the full Host object
- * @throws ConfigurationException if an error occurred within or during
- * communication with the Configuration Service, or if there is no object
- * for the given ID.
- */
- public Host getDefaultHost() {
- String name = getBootStrapProperties().getProperty(CONFIGURATION_NAME, "embedded"); //$NON-NLS-1$
- BasicHost host = new BasicHost(new ConfigurationID(name), new HostID(name), Host.HOST_COMPONENT_TYPE_ID);
-
- Properties props = new Properties();
- props.setProperty(com.metamatrix.admin.api.objects.Host.INSTALL_DIR, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.INSTALL_DIR, System.getProperty("user.dir"))); //$NON-NLS-1$
- props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_DIRECTORY, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_DIRECTORY, System.getProperty("user.dir"))); //$NON-NLS-1$
- props.setProperty(com.metamatrix.admin.api.objects.Host.LOG_DIRECTORY, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.LOG_DIRECTORY, System.getProperty("user.dir"))); //$NON-NLS-1$
- props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_BIND_ADDRESS, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_BIND_ADDRESS, "")); //$NON-NLS-1$
- props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_PHYSICAL_ADDRESS, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_PHYSICAL_ADDRESS, "")); //$NON-NLS-1$
-
- host.setProperties(props);
- return host;
- }
-
-
- /**
- * Reset causes not just a refresh, but the bootstrapping process
- * to occur again.
- */
- public static void reset() {
- INSTANCE = new CurrentConfiguration();
- }
-
- public synchronized Properties getBootStrapProperties() {
- if (bootstrapProperties == null) {
- Properties systemBootStrapProps = getSystemBootStrapProperties();
- Properties bootstrapProps = new Properties(systemBootStrapProps);
- InputStream bootstrapPropStream = null;
-
- String bootstrapfile = systemBootStrapProps.getProperty(BOOTSTRAP_FILE_PROPERTY_OVERRIDE, BOOTSTRAP_FILE_NAME);
- try {
- bootstrapPropStream = this.getClass().getClassLoader().getResourceAsStream(bootstrapfile);
- if (bootstrapPropStream != null) {
- bootstrapProps.load(bootstrapPropStream);
- }
- } catch (IOException e) {
- throw new MetaMatrixRuntimeException(ErrorMessageKeys.CONFIG_ERR_0069, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0069, BOOTSTRAP_FILE_NAME));
- } finally {
- try {
- if (bootstrapPropStream != null) {
- bootstrapPropStream.close();
- }
- } catch (IOException e ) {
- }
- }
- modifyableBootstrapProperties = bootstrapProps;
- bootstrapProperties = new UnmodifiableProperties(bootstrapProps);
- }
- return bootstrapProperties;
- }
-
- public synchronized final Properties getSystemBootStrapProperties() {
- if (systemBootstrapProperties == null) {
- systemBootstrapProperties = new UnmodifiableProperties(System.getProperties());
- }
- return systemBootstrapProperties;
- }
-
- synchronized CurrentConfigurationReader getReader() throws ConfigurationException {
- if (reader == null) {
- // Get the default bootstrap properties from the System properties ...
- Properties bootstrap = getBootStrapProperties();
-
- String readerClassName = bootstrap.getProperty( CONFIGURATION_READER_CLASS_PROPERTY_NAME, PropertiesConfigurationReader.class.getName() );
-
- try {
- reader = (CurrentConfigurationReader)ReflectionHelper.create(readerClassName, null, Thread.currentThread().getContextClassLoader());
- } catch (Exception e) {
- throw new ConfigurationException(e);
- }
- }
-
- return reader;
- }
-}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/ResourceNames.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/ResourceNames.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/ResourceNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config;
-
-/**
-* ResourceNames defines the different resources that require
-* connection properties. These properties are loaded up by
-* the {@link CurrentConfiguration} and made available by calling
-* the method {@link #getResourceProperties}. The following
-* are the basis for the names:
-* - CompTypes, excluding connectors (e.g., Config Service, Session Service, etc).
-* - internal operations (e.g., Runtime Metadata, logging, cursors, etc.)
-*/
-public interface ResourceNames {
-
-
- public static final String RUNTIME_METADATA_SERVICE = "RuntimeMetadataService"; //$NON-NLS-1$
- public static final String MEMBERSHIP_SERVICE = "MembershipService"; //$NON-NLS-1$
- public static final String XA_TRANSACTION_MANAGER = "XATransactionManager"; //$NON-NLS-1$
- public static final String INDEXING_SERVICE = "IndexingService"; //$NON-NLS-1$
- public static final String JGROUPS = "JGroups"; //$NON-NLS-1$
- public static final String SSL = "SSL"; //$NON-NLS-1$
-}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.model;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.api.ComponentDefn;
-import com.metamatrix.common.config.api.ComponentType;
-import com.metamatrix.common.config.api.ComponentTypeDefn;
-import com.metamatrix.common.config.api.ConfigurationModelContainer;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.common.object.PropertyDefinition;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.common.util.crypto.CryptoUtil;
-import com.metamatrix.core.util.Assertion;
-
-
-/**
- * Utilities for encrypting and decrypting properties of configuration ComponentDefns
- * @since 4.3
- */
-public class ComponentCryptoUtil {
-
-
- /**
- * Check whether the encrypted properties for the specified ComponentDefn can be decrypted.
- * @param defn The ComponentDefn to check.
- * @param componentTypeDefns Collection<ComponentTypeDefn> The ComponentTypeDefns containing the
- * PropertyDefinitions for the specified ComponentDefn.
- * @return true if the properties could be decrypted for that defn.
- * @since 4.3
- */
- public static boolean checkPropertiesDecryptable(ComponentDefn defn, Collection componentTypeDefns) {
- boolean result = true;
-
- try {
- decryptProperties(defn, componentTypeDefns);
- } catch (CryptoException e) {
- result = false;
- }
-
- return result;
- }
-
- /**
- * Bails on the first masked property name that's contained in props but the value
- * can't be decrypted. All masked properties that exist in props must be decryptable.
- * @param props
- * @param componentTypeIdentifier
- * @return
- * @since 4.3
- */
- public static boolean checkPropertiesDecryptable(Properties props,
- Collection maskedPropertyNames) {
- if (maskedPropertyNames != null) {
- Iterator propItr = maskedPropertyNames.iterator();
- while (propItr.hasNext()) {
- String maskedPropName = (String)propItr.next();
- String maskedValue = null;
- if (props != null) {
- maskedValue = props.getProperty(maskedPropName);
- }
- if (maskedValue != null && !CryptoUtil.canDecrypt(maskedValue)) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- public static Properties getDecryptedProperties(ComponentDefn defn) throws ConfigurationException, CryptoException {
- ConfigurationModelContainer configModel = CurrentConfiguration.getInstance().getConfigurationModel();
-
- ComponentType componentType = configModel.getComponentType(defn.getComponentTypeID().getName());
- Assertion.isNotNull(componentType, "unknown component type"); //$NON-NLS-1$
-
- Collection compTypeDefns = componentType.getComponentTypeDefinitions();
- return decryptProperties(defn, compTypeDefns);
- }
-
- private static Properties decryptProperties(ComponentDefn defn,
- Collection compTypeDefns) throws CryptoException {
- Properties result = PropertiesUtils.clone(defn.getProperties(), false);
- for ( Iterator compTypeDefnItr = compTypeDefns.iterator(); compTypeDefnItr.hasNext(); ) {
- ComponentTypeDefn typeDefn = (ComponentTypeDefn) compTypeDefnItr.next();
- PropertyDefinition propDefn = typeDefn.getPropertyDefinition();
- String propName = propDefn.getName();
- String propValue = result.getProperty(propName);
- if ( propValue != null && propDefn.isMasked() ) {
- propValue = CryptoUtil.getDecryptor().decrypt(propValue);
- result.setProperty(propName, propValue);
- }
- }
-
- return result;
- }
-
-}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,140 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.model;
-
-import java.util.Iterator;
-import java.util.List;
-
-import com.metamatrix.common.CommonPlugin;
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.core.util.StringUtil;
-
-
-
-
-/**
- * @since 4.3
- */
-public class PropertyValidations {
-
-
-
- public static final String UDP_MCAST_ADDR_PROPERTY = "udp.mcast_addr"; //$NON-NLS-1$
- public static final String SYSTEM_NAME = CurrentConfiguration.CLUSTER_NAME;
-
- private static final String MULTICAST_PORT_FORMAT = "224.255.255.255"; //$NON-NLS-1$
-
-
- /**
- * @see com.metamatrix.common.util.commandline.IPropertyValidation#isPropertyValid(java.lang.String, java.lang.String)
- * @since 4.3
- */
- public void isPropertyValid(String key,
- String value) throws ConfigurationException {
-
- if (key == null) {
- return;
- }
- if (key.equalsIgnoreCase(UDP_MCAST_ADDR_PROPERTY)) {
- validate_multicast_port(key, value);
- }
-
- if (key.equalsIgnoreCase(SYSTEM_NAME)) {
- validate_nonnull_and_contiguous("System Name", key, value);//$NON-NLS-1$
- }
- }
-
- protected void validate_multicast_port(String key, String value) throws ConfigurationException {
- if (value == null || value.trim().length() == 0) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_format", new Object[] {"MulticastPort", "Null", MULTICAST_PORT_FORMAT} )); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- List parts = StringUtil.getTokens(value, "."); //$NON-NLS-1$
- // the port must have 4 parts
- if (parts.size() != 4) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_format", new Object[] {"MulticastPort", value, MULTICAST_PORT_FORMAT} )); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- validate_nonnull_and_contiguous("MulticastPort", key, value); //$NON-NLS-1$
-
- // verify each part is numeric
- for (Iterator it=parts.iterator(); it.hasNext();) {
- String part = (String) it.next();
- if (isInvalidNumeric(part )) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_numeric_value", new Object[] {part, ", must be between 0 and 255"} )); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- validate_port_range(key, part, 0, 255);
- }
-
-
- }
-
- protected void validate_port_range(String key, String value, int start, int end) throws ConfigurationException {
- if (value == null || value.trim().length() == 0) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_format", new Object[] {key, "Null", "Range " + start + " and " + end } )); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
- Long nbr = null;
- try {
- nbr = new Long(value);
- } catch (NumberFormatException nfe) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_numeric_value", new Object[] {key, ", must be between " + start + " and " + end} )); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- if (nbr.longValue() >= start && nbr.longValue() <= end) {
-
- }else {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_numeric_value", new Object[] {key, ", must be between " + start + " and " + end} )); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
-
- }
-
- protected void validate_nonnull_and_contiguous(String display, String key, String value) throws ConfigurationException {
- if (value == null || value.trim().length() == 0) {
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_contiguous_value", new Object[] {display} )); //$NON-NLS-1$
- }
-
- if (value.indexOf(" ") > 0) { //$NON-NLS-1$
- throwException(CommonPlugin.Util.getString("PropertyValidation.Invalid_contiguous_value", new Object[] {display} )); //$NON-NLS-1$
- }
-
- }
-
- protected void throwException(String msg) throws ConfigurationException {
- throw new ConfigurationException(msg);
-
- }
-
- protected boolean isInvalidNumeric(String value) {
- try {
- new Long(value);
- return false;
- } catch (NumberFormatException nfe) {
- return true;
- }
- }
-
-}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/CurrentConfigurationReader.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/CurrentConfigurationReader.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/CurrentConfigurationReader.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.reader;
-
-import com.metamatrix.common.config.api.ConfigurationModelContainer;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-
-/**
- * <p>
- * This interface defines a self-contained reader for the current configuration,
- * and should be used <i>only</i> by the {@link com.metamatrix.common.config.CurrentConfiguration CurrentConfiguration}
- * framework. As such, this is an extremely low-level implementation that may
- * <i>not</i> use anything but <code>com.metamatrix.common.util</code> components
- * and only components that do not use {@link com.metamatrix.common.logging.LogManager LogManager}.
- * </p>
- * <p>
- * Each class that implements this interface must supply a no-arg constructor.
- * </p>
- */
-public interface CurrentConfigurationReader {
-
- // ------------------------------------------------------------------------------------
- // C O N F I G U R A T I O N I N F O R M A T I O N
- // ------------------------------------------------------------------------------------
-
- /**
- * Obtain the next startup configuration model. The implementation
- * may <i>not</i> use logging but instead should rely upon returning
- * an exception in the case of any errors.
- * @return the serializable Configuration instance
- * @throws ConfigurationException if an error occurred within or during
- * communication with the repository.
- */
- ConfigurationModelContainer getConfigurationModel() throws ConfigurationException;
-
-}
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/PropertiesConfigurationReader.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/PropertiesConfigurationReader.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/reader/PropertiesConfigurationReader.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,124 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.reader;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import com.metamatrix.common.CommonPlugin;
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.api.Configuration;
-import com.metamatrix.common.config.api.ConfigurationModelContainer;
-import com.metamatrix.common.config.api.ConfigurationObjectEditor;
-import com.metamatrix.common.config.api.exceptions.ConfigurationConnectionException;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.common.config.model.BasicConfigurationObjectEditor;
-import com.metamatrix.common.config.model.ConfigurationModelContainerImpl;
-import com.metamatrix.common.util.ErrorMessageKeys;
-
-/**
- * <p>
- * This class implements a self-contained reader for the current configuration,
- * and should be used <i>only</i> by the {@link com.metamatrix.common.config.CurrentConfiguration CurrentConfiguration}
- * framework. As such, this is an extremely low-level implementation that may
- * <i>not</i> use anything but <code>com.metamatrix.common.util</code> components
- * and only components that do not use {@link com.metamatrix.common.logging.LogManager LogManager}.
- * </p>
- * <p>
- * Each class that implements this interface must supply a no-arg constructor.
- * </p>
- */
-public class PropertiesConfigurationReader implements CurrentConfigurationReader {
-
- private ConfigurationModelContainer c;
-
- /**
- * The environment property name for the property file that contains the configuration.
- */
- public static final String FILENAME = "metamatrix.config.readerFile"; //$NON-NLS-1$
-
- /**
- * Default, no-arg constructor
- * @throws ConfigurationException
- * @throws ConfigurationConnectionException
- */
- public PropertiesConfigurationReader() throws ConfigurationConnectionException, ConfigurationException{
- Properties env = CurrentConfiguration.getInstance().getBootStrapProperties();
- String filename = env.getProperty(FILENAME);
- Properties p = null;
- if (filename != null) {
- File f = new File(filename);
- InputStream is = null;
- try {
- if (f.exists()) {
- is = new FileInputStream(f);
- } else {
- is = this.getClass().getResourceAsStream(filename);
- }
- if (is == null) {
- throw new ConfigurationConnectionException(ErrorMessageKeys.CONFIG_ERR_0064, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0064, filename));
- }
- p = new Properties(env);
- p.load(is);
- } catch (IOException e) {
- throw new ConfigurationConnectionException(e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
- } else {
- p = env;
- }
-
- // Use the properties from the file to create a new Configuration object ...
- ConfigurationObjectEditor coe = new BasicConfigurationObjectEditor(false);
- Configuration currentConfiguration = coe.createConfiguration(PropertiesConfigurationReader.class.getSimpleName() + ':' + filename);
- currentConfiguration = (Configuration)coe.modifyProperties(currentConfiguration, p, ConfigurationObjectEditor.SET);
- c = new ConfigurationModelContainerImpl(currentConfiguration);
- }
-
- // ------------------------------------------------------------------------------------
- // C O N F I G U R A T I O N I N F O R M A T I O N
- // ------------------------------------------------------------------------------------
-
- /**
- * Obtain the next startup configuration model. The implementation
- * may <i>not</i> use logging but instead should rely upon returning
- * an exception in the case of any errors.
- * @return the serializable Configuration instance
- * @throws ConfigurationException if an error occurred within or during
- * communication with the repository.
- */
- public ConfigurationModelContainer getConfigurationModel() throws ConfigurationException {
- return c;
- }
-
-}
-
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigurationPropertyNames.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigurationPropertyNames.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigurationPropertyNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -35,11 +35,5 @@
// needs to be change, which will impact the importing of .DEF files.
static final double CONFIG_CURR_VERSION_DBL = 6.0;
static final String CONFIG_CURR_VERSION = "6.0";
-
-
- public static final String MEMBERSHIP_ADMIN_PASSWORD = "security.membership.admin.password"; //$NON-NLS-1$
- public static final String MEMBERSHIP_ADMIN_USERNAME = "security.membership.admin.username"; //$NON-NLS-1$
- public static final String MEMBERSHIP_SECURITY_ENABLED = "security.membership.security.enabled"; //$NON-NLS-1$
- public static final String MEMBERSHIP_DOMAIN_ORDER = "security.membership.DomainOrder"; //$NON-NLS-1$
-
+
}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/util/CommonPropertyNames.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/CommonPropertyNames.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/CommonPropertyNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-
-/**
- * Class that defines common property constants
- */
-public final class CommonPropertyNames {
-
- public static final String DOMAIN_ID = "metamatrix.siteID"; //$NON-NLS-1$
-
- public static final String RMI_CONTEXT_FACTORY = "metamatrix.deployment.rmiContextFactory"; //$NON-NLS-1$
-
- public static final String BEAN_CONTEXT_FACTORY = "metamatrix.deployment.beanContextFactory"; //$NON-NLS-1$
-
- public static final String DEFAULT_JNDI_URL = "metamatrix.deployment.defaultJndiURL"; //$NON-NLS-1$
-
- /**
- * <p>This property indicates the VM is running inside an
- * ApplicationServer. If the property exists and is set to true</p>
- * <p>This is an optional property</p>
- */
- public static final String APP_SERVER_VM = "metamatrix.appserver_vm"; //$NON-NLS-1$
- /**
- * <p>This property indicates the EJB server platform which the MetaMatrix
- * server is running on. Currently the only two possible values are
- * IBM's {@link #WEBSPHERE_PLATFORM WebSphere} server, and
- * the {@link #WEBLOGIC_PLATFORM Weblogic} server. The MetaMatrix
- * server</p>
- * <p>This is a required property</p>
- */
- public static final String SERVER_PLATFORM = "metamatrix.deployment.platform"; //$NON-NLS-1$
-
-
- /**
- * <p>This constant defines one of the possible values for the
- * {@link #SERVER_PLATFORM} property. It indicates that
- * no application server is running.</p>
- * <p>This is not a property, but rather a possible value for
- * the {@link #SERVER_PLATFORM} property.</p>
- */
- public static final String STANDALONE_PLATFORM = "standalone"; //$NON-NLS-1$
-
- /**
- * This is the installation directory defined by the bootstrapping process.
- * The bootstrapping information will provide this property by which the
- * {@link #CurrentConfiguration.getProperty()} will return.
- * @since 4.0
- */
- public static final String INSTALLATION_DIRECTORY = "metamatrix.installationDir"; //$NON-NLS-1$
-
- /**
- * This is the location the configuration models are located. This
- * property is used by the installation and configuration persistent components.
- */
- public static final String CONFIG_MODELS_DIRECTORY = "metamatrix.config.modelsDir"; //$NON-NLS-1$
-
- /**
- * The date of installation of the MetaMatrix suite
- */
- public static final String INSTALL_DATE = "metamatrix.installationDate"; //$NON-NLS-1$
-
-
- /**
- * This is the property name of the MetaMatrixAdmin password.
- */
- public static final String ADMIN_PASSWORD = "metamatrix.admin.password"; //$NON-NLS-1$
-
- /**
- * This is the property name of the MetaMatrixAdmin username.
- */
- public static final String ADMIN_USERNAME = "metamatrix.admin.username"; //$NON-NLS-1$
-
-
- /**
- * If this property is set to true then client side encryption is enabled.
- */
- public static final String CLIENT_ENCRYPTION_ENABLED = "metamatrix.encryption.client.encryption"; //$NON-NLS-1$
-
- /**
- * This property indicates the encryption provider, if set to none encryption is disabled.
- */
- public static final String JCE_PROVIDER = "metamatrix.encryption.jce.provider"; //$NON-NLS-1$
-
-
- /**
- * Extension Module file types to cache in memory.
- * Should be comma-delimited list of values as stored in
- * JDBCNames.ExtensionFilesTable.ColumnName.FILE_TYPE.
- * For example: "JAR File, Function Definition".
- * Default is none.
- */
- public static final String EXTENSION_TYPES_TO_CACHE = "metamatrix.server.extensionTypesToCache"; //$NON-NLS-1$
-
-
-}
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/util/LogConstants.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/LogConstants.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/LogConstants.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -31,4 +31,6 @@
public static final String CTX_MEMBERSHIP = "MEMBERSHIP"; //$NON-NLS-1$
public static final String CTX_AUTHORIZATION = "AUTHORIZATION"; //$NON-NLS-1$
public static final String CTX_AUTHORIZATION_ADMIN_API = "AUTHORIZATION_ADMIN_API"; //$NON-NLS-1$
+ public static final String CTX_SERVER= "Server"; //$NON-NLS-1$
+ public static final String CTX_ADMIN = "ADMIN"; //$NON-NLS-1$
}
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/util/crypto/keymanage/FilePasswordConverter.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/crypto/keymanage/FilePasswordConverter.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/crypto/keymanage/FilePasswordConverter.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -37,7 +37,6 @@
import org.jdom.Document;
import org.jdom.Element;
-import com.metamatrix.common.util.CommonPropertyNames;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.util.crypto.CryptoUtil;
import com.metamatrix.common.util.crypto.PasswordChangeUtility;
@@ -58,8 +57,7 @@
public static final int FILE_TYPE_PROPERTIES = 2;
public static final int FILE_TYPE_VDB = 3;
- private static String DEFAULT_KEY_FILE = System.getProperty(CommonPropertyNames.INSTALLATION_DIRECTORY) + File.separator
- + "config" + File.separator + CryptoUtil.KEY_NAME; //$NON-NLS-1$
+ private static String DEFAULT_KEY_FILE = CryptoUtil.KEY_NAME;
private static final String PASSWORD = "PASSWORD"; //$NON-NLS-1$
Modified: trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties
===================================================================
--- trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -3095,7 +3095,7 @@
VDBArchiveSotRef.Unable_to_reead_file=Failed to read the specific file {0}
URIResource.Resource_not_found=Resource {0} could not be found or loaded in order to know what type of model classes to entitle.
-BasicApplication.Failed_while_installing_service_of_type__1=Failed while installing service of type
+BasicApplication.Failed_while_installing_service_of_type__1=Failed while installing service of type
VDBDefnXMLHelper.Unable_to_read_defn_file=Unable to read DEF file.
Deleted: trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestComponentCryptoUtil.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestComponentCryptoUtil.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestComponentCryptoUtil.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,151 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.model;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.api.ComponentTypeDefn;
-import com.metamatrix.common.config.api.ComponentTypeDefnID;
-import com.metamatrix.common.config.api.ConnectorBindingID;
-import com.metamatrix.common.config.reader.PropertiesConfigurationReader;
-import com.metamatrix.common.object.PropertyDefinitionImpl;
-import com.metamatrix.common.util.crypto.CryptoUtil;
-
-
-public class TestComponentCryptoUtil extends TestCase {
-
-
- private static String ENCRYPTED;
- private final static String NOT_ENCRYPTED = "not decrypted"; //$NON-NLS-1$
-
-
- public TestComponentCryptoUtil(String name) throws Exception {
- super(name);
- }
-
-
- public void setUp() throws Exception {
- System.setProperty(CurrentConfiguration.CONFIGURATION_READER_CLASS_PROPERTY_NAME, PropertiesConfigurationReader.class.getName());
- ENCRYPTED = new String(CryptoUtil.stringEncrypt("password")); //$NON-NLS-1$
- }
-
- public void testCheckPropertiesDecryptable() throws Exception {
- BasicComponentDefn defn = new BasicConnectorBinding(null, new ConnectorBindingID(null, "binding"), null); //$NON-NLS-1$
-
- //positive case
- List componentTypeDefns = new ArrayList();
-
- helpSetProperty(defn, componentTypeDefns, "prop1", ENCRYPTED, true); //$NON-NLS-1$
- helpSetProperty(defn, componentTypeDefns, "prop2", NOT_ENCRYPTED, false); //$NON-NLS-1$
-
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable(defn, componentTypeDefns);
- assertTrue(decryptable);
-
-
-
- //negative case
- componentTypeDefns = new ArrayList();
-
- helpSetProperty(defn, componentTypeDefns, "prop1", ENCRYPTED, true); //$NON-NLS-1$
- helpSetProperty(defn, componentTypeDefns, "prop2", NOT_ENCRYPTED, true); //$NON-NLS-1$
-
- decryptable = ComponentCryptoUtil.checkPropertiesDecryptable(defn, componentTypeDefns);
- assertFalse(decryptable);
-
- }
-
-
-
- /**
- * Helper method that sets a property on a ComponentDefn, and adds it to a list of ComponentTypeDefns
- *
- * @since 4.3
- */
- private void helpSetProperty(BasicComponentDefn defn, List componentTypeDefns, String key, String value, boolean isMasked) {
- //set on the ComponentDefn
- defn.addProperty(key, value);
-
- //create a ComponentTypeDefn and add to the list
- PropertyDefinitionImpl pd = new PropertyDefinitionImpl();
- pd.setName(key);
- pd.setMasked(isMasked);
- ComponentTypeDefn ctd = new BasicComponentTypeDefn(new ComponentTypeDefnID(key), null, pd, false, false);
- componentTypeDefns.add(ctd);
- }
-
- public void testCheckPropertiesDecryptableEmpty() throws Exception {
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable(new Properties(), new ArrayList());
- assertTrue("Expected true ", decryptable); //$NON-NLS-1$
- }
-
- public void testCheckPropertiesDecryptableNull() throws Exception {
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable((Properties)null, (Collection)null);
- assertTrue("Expected true ", decryptable); //$NON-NLS-1$
- }
-
- public void testCheckPropertiesDecryptableNullProperties() throws Exception {
- Collection maskedNames = new ArrayList();
- maskedNames.add("Roberto"); //$NON-NLS-1$
- maskedNames.add("Pietro"); //$NON-NLS-1$
- maskedNames.add("Digiorno"); //$NON-NLS-1$
- maskedNames.add("Digragorio"); //$NON-NLS-1$
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable((Properties)null, maskedNames);
- assertTrue("Expected true ", decryptable); //$NON-NLS-1$
- }
-
- public void testCheckPropertiesDecryptableFail() throws Exception {
- String maskedPropName = "password"; //$NON-NLS-1$
- Collection maskedNames = new ArrayList();
- maskedNames.add(maskedPropName);
-
- Properties props = new Properties();
- props.setProperty(maskedPropName, "mm"); //$NON-NLS-1$
-
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable(props, maskedNames);
- assertFalse("Expected not decryptable ", decryptable); //$NON-NLS-1$
- }
-
- public void testCheckPropertiesDecryptablePass() throws Exception {
- String maskedPropName = "password"; //$NON-NLS-1$
- Collection maskedNames = new ArrayList();
- maskedNames.add(maskedPropName);
-
- Properties props = new Properties();
- props.setProperty(maskedPropName, ENCRYPTED); //$NON-NLS-1$
-
- boolean decryptable = ComponentCryptoUtil.checkPropertiesDecryptable(props, maskedNames);
- assertTrue("Expected decryptable ", decryptable); //$NON-NLS-1$
- }
-
-
-
-}
-
-
Deleted: trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestPropertyValidation.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestPropertyValidation.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/config/model/TestPropertyValidation.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,69 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.config.model;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-
-public class TestPropertyValidation extends TestCase {
-
- /**
- * @param name
- */
- public TestPropertyValidation(String name) {
- super(name);
-
- }
-
- // ################################## TESTS ################################
-
- public void testBoundariesMultiCastPort() throws Exception{
- PropertyValidations val = new PropertyValidations();
- val.isPropertyValid(PropertyValidations.UDP_MCAST_ADDR_PROPERTY, "224.0.0.0" ); //$NON-NLS-1$
-
- val.isPropertyValid(PropertyValidations.UDP_MCAST_ADDR_PROPERTY, "224.255.255.255" ); //$NON-NLS-1$
-
- }
-
- public void testInvalidAlphaMultiCastPort() throws Exception{
- try {
- PropertyValidations val = new PropertyValidations();
- val.isPropertyValid(PropertyValidations.UDP_MCAST_ADDR_PROPERTY, "224.a.c.d" ); //$NON-NLS-1$
- fail("224.a.c.d multicast port has alpha characters and is invalid"); //$NON-NLS-1$
- } catch (ConfigurationException ce) {
-
- }
- }
-
- public void testMissingNodesMultiCastPort() throws Exception{
- try {
- PropertyValidations val = new PropertyValidations();
- val.isPropertyValid(PropertyValidations.UDP_MCAST_ADDR_PROPERTY, "224.10." ); //$NON-NLS-1$
- fail("224.10. multicast port is missing nodes and is invalid"); //$NON-NLS-1$
- } catch (ConfigurationException ce) {
-
- }
- }
-
-}
Modified: trunk/embedded/pom.xml
===================================================================
--- trunk/embedded/pom.xml 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/pom.xml 2009-06-26 22:06:04 UTC (rev 1088)
@@ -68,6 +68,11 @@
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ </dependency>
+
</dependencies>
</project>
\ No newline at end of file
Deleted: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,105 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.dqp.embedded;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.teiid.dqp.internal.cache.DQPContextCache;
-
-import com.google.inject.Binder;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-import com.google.inject.name.Names;
-import com.metamatrix.common.application.ApplicationService;
-import com.metamatrix.common.application.DQPConfigSource;
-import com.metamatrix.common.application.exception.ApplicationInitializationException;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.dqp.embedded.services.EmbeddedBufferService;
-import com.metamatrix.dqp.embedded.services.EmbeddedConfigurationService;
-import com.metamatrix.dqp.embedded.services.EmbeddedDataService;
-import com.metamatrix.dqp.embedded.services.EmbeddedMetadataService;
-import com.metamatrix.dqp.embedded.services.EmbeddedTransactionService;
-import com.metamatrix.dqp.embedded.services.EmbeddedVDBService;
-import com.metamatrix.dqp.service.DQPServiceNames;
-
-/**
- * This class is main hook point for the Embedded DQP configuration. This classe's
- * responsibility is to encapsulate the knowledge of creating of the various application
- * services used the DQP.
- *
- */
-@Singleton
-public class EmbeddedConfigSource implements DQPConfigSource {
-
- private Properties props;
- private boolean useTxn;
- private URL dqpURL;
-
- @Inject
- DQPContextCache contextCache;
-
- /**
- * Based the configuration file load the DQP services
- * @param configFile
- * @throws ApplicationInitializationException
- */
- @Inject public EmbeddedConfigSource(@Named("BootstrapURL") URL dqpURL, @Named("DQPProperties") Properties connectionProperties) {
- this.dqpURL = dqpURL;
- this.props = connectionProperties;
- useTxn = PropertiesUtils.getBooleanProperty(props, EmbeddedTransactionService.TRANSACTIONS_ENABLED, true);
- }
-
- /**
- * @see com.metamatrix.common.application.DQPConfigSource#getProperties()
- */
- public Properties getProperties() {
- return this.props;
- }
-
- @Override
- public void updateBindings(Binder binder) {
- if (contextCache != null) {
- binder.bind(DQPContextCache.class).toInstance(contextCache);
- }
- binder.bind(URL.class).annotatedWith(Names.named("BootstrapURL")).toInstance(this.dqpURL); //$NON-NLS-1$
- }
-
- @Override
- public Map<String, Class<? extends ApplicationService>> getDefaultServiceClasses() {
- Map<String, Class<? extends ApplicationService>> result = new HashMap<String, Class<? extends ApplicationService>>();
- result.put(DQPServiceNames.CONFIGURATION_SERVICE, EmbeddedConfigurationService.class);
- result.put(DQPServiceNames.BUFFER_SERVICE, EmbeddedBufferService.class);
- result.put(DQPServiceNames.VDB_SERVICE, EmbeddedVDBService.class);
- result.put(DQPServiceNames.METADATA_SERVICE, EmbeddedMetadataService.class);
- result.put(DQPServiceNames.DATA_SERVICE, EmbeddedDataService.class);
- if (useTxn) {
- result.put(DQPServiceNames.TRANSACTION_SERVICE, EmbeddedTransactionService.class);
- }
- return result;
- }
-
-}
Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1494,5 +1494,10 @@
Properties getUserPreferences() {
return userPreferences;
}
+
+ @Override
+ public String getClusterName() {
+ return getUserPreferences().getProperty(DQPEmbeddedProperties.CLUSTERNAME, "embedded"); //$NON-NLS-1$
+ }
}
Deleted: trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnection.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnection.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.jdbc;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import com.metamatrix.admin.api.core.Admin;
-import com.metamatrix.admin.api.embedded.EmbeddedAdmin;
-import com.metamatrix.admin.api.exception.AdminProcessingException;
-import com.metamatrix.common.comm.api.ServerConnection;
-import com.metamatrix.core.util.MixinProxy;
-import com.metamatrix.dqp.embedded.admin.DQPConfigAdminImpl;
-import com.metamatrix.dqp.embedded.admin.DQPMonitoringAdminImpl;
-import com.metamatrix.dqp.embedded.admin.DQPRuntimeStateAdminImpl;
-import com.metamatrix.dqp.embedded.admin.DQPSecurityAdminImpl;
-
-/**
- * This class simple wrapper on top of MMConnection for the EmbeddedDriver and
- * EmbeddedDataSource.
- *
- * The specific reason for this class is to have a management API on the
- * a JDBC Connection.
- *
- * @since 4.3
- */
-public class EmbeddedConnection extends MMConnection {
-
- // constant value giving product name
- private final static String SERVER_NAME = "Teiid Embedded"; //$NON-NLS-1$
-
- EmbeddedConnectionFactoryImpl manager = null;
- ConnectionListener listener = null;
-
- /**
- * ctor
- */
- public EmbeddedConnection(EmbeddedConnectionFactoryImpl manager, ServerConnection serverConn, Properties info, ConnectionListener listener) {
- super(serverConn, info, null);
- this.manager = manager;
- this.listener = listener;
-
- // tell the listener that connection has been created
- if (listener != null) {
- this.listener.connectionAdded(getConnectionId(), this);
- }
- }
-
- /**
- * Get the Admin API interface, so that the caller can manager various aspects of configuring the DQP, like adding, deleteing
- * a VDB. Look at Java Docs for <code>Admin</code> all supported functionality.
- *
- * @return retuns reference to API, never null.
- * @since 4.3
- */
- public Admin getAdminAPI() throws SQLException {
-
- InvocationHandler handler = new MixinProxy(new Object[] {
- new DQPConfigAdminImpl(manager),
- new DQPMonitoringAdminImpl(manager),
- new DQPRuntimeStateAdminImpl(manager),
- new DQPSecurityAdminImpl(manager)
- }) {
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- // We we perform any DQP functions check if the DQP is still alive
- if (!manager.isAlive()) {
- throw new AdminProcessingException(JDBCPlugin.Util.getString("EmbeddedConnection.DQP_shutDown")); //$NON-NLS-1$
- }
-
- // Since all the loading is done by the executing threads class loader, by defination we need to
- // switch to our local non-delegating class loader each time the class enters into the dqp connection
- // boundary, however for simplicity sake we have only put this barrier, in the comm layer to isolate the
- // DQP code however the com.mm.jdbc.sql code will still use the calling class loader. By changing the
- // class loader here, I am at atleast avoiding the classloading issues for the Admin code. - rreddy.
- ClassLoader callingClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- // Set the class loader to current class classloader so that the this classe's class loader gets used
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- return super.invoke(proxy, method, args);
- }
- finally {
- Thread.currentThread().setContextClassLoader(callingClassLoader);
- }
- }
- };
- return (EmbeddedAdmin) Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[] {EmbeddedAdmin.class}, handler);
- }
-
- /**
- * @see com.metamatrix.jdbc.MMConnection#getDatabaseName()
- */
- @Override
- public String getDatabaseName() {
- return SERVER_NAME;
- }
-
- @Override
- public BaseDriver getBaseDriver() {
- return new EmbeddedDriver();
- }
-
- @Override
- public boolean isSameProcess(MMConnection conn) {
- return (conn instanceof EmbeddedConnection);
- }
-
- @Override
- public void close() throws SQLException {
- if (this.listener != null) {
- this.listener.connectionRemoved(getConnectionId(), this);
- }
- super.close();
- }
-}
Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,34 +22,66 @@
package com.metamatrix.jdbc;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.MalformedURLException;
import java.net.URL;
-import java.sql.Connection;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
import org.teiid.dqp.internal.process.DQPCore;
+import org.teiid.transport.AdminAuthorizationInterceptor;
+import org.teiid.transport.LocalServerConnection;
+import org.teiid.transport.LogonImpl;
+import org.teiid.transport.SocketTransport;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.metamatrix.admin.api.core.Admin;
+import com.metamatrix.admin.api.embedded.EmbeddedAdmin;
+import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.admin.api.exception.AdminProcessingException;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.application.ApplicationService;
-import com.metamatrix.common.application.DQPConfigSource;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
+import com.metamatrix.common.comm.ClientServiceRegistry;
import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.api.ServerConnectionFactory;
+import com.metamatrix.common.comm.api.ServerConnectionListener;
+import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.common.comm.exception.ConnectionException;
import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.protocol.URLHelper;
+import com.metamatrix.common.util.JMXUtil;
+import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.vdb.api.VDBArchive;
import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.MixinProxy;
import com.metamatrix.dqp.ResourceFinder;
+import com.metamatrix.dqp.client.ClientSideDQP;
import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
+import com.metamatrix.dqp.embedded.admin.DQPConfigAdminImpl;
+import com.metamatrix.dqp.embedded.admin.DQPMonitoringAdminImpl;
+import com.metamatrix.dqp.embedded.admin.DQPRuntimeStateAdminImpl;
+import com.metamatrix.dqp.embedded.admin.DQPSecurityAdminImpl;
+import com.metamatrix.dqp.service.AuthorizationService;
import com.metamatrix.dqp.service.ConfigurationService;
import com.metamatrix.dqp.service.DQPServiceNames;
import com.metamatrix.dqp.service.VDBService;
import com.metamatrix.dqp.util.LogConstants;
-import com.metamatrix.jdbc.transport.LocalTransportHandler;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
/**
@@ -57,31 +89,47 @@
* This is also responsible for initializing the DQP if the DQP instance is not
* already alive.
*/
-public class EmbeddedConnectionFactoryImpl implements EmbeddedConnectionFactory {
- private static final int ACTIVE = 3;
- private LocalTransportHandler handler = null;
+public class EmbeddedConnectionFactoryImpl implements ServerConnectionFactory {
private volatile boolean shutdownInProgress = false;
private DQPCore dqp;
private long starttime = -1L;
private Thread shutdownThread;
+ private ClientServiceRegistry clientServices;
+ private String workspaceDirectory;
+ private boolean init = false;
+ private ConnectionListenerList listenerList = new ConnectionListenerList();
+ private SocketTransport socketTransport;
+ private JMXUtil jmxServer;
+
+ private final class ConnectionListenerList extends ArrayList<ServerConnectionListener> implements ServerConnectionListener{
- /**
- * @see com.metamatrix.jdbc.EmbeddedConnectionFactory#createConnection()
- */
- public Connection createConnection(Properties props) throws SQLException {
+ @Override
+ public void connectionAdded(ServerConnection connection) {
+ for (ServerConnectionListener l: this) {
+ l.connectionAdded(connection);
+ }
+ }
+ @Override
+ public void connectionRemoved(ServerConnection connection) {
+ for (ServerConnectionListener l: this) {
+ l.connectionRemoved(connection);
+ }
+ }
+ }
+
+ @Override
+ public ServerConnection createConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
try {
- // check for the valid connection properties
- checkConnectionProperties (props);
+
+ initialize(connectionProperties);
+ return new LocalServerConnection(connectionProperties, this.clientServices, listenerList);
- ServerConnection serverConn = this.handler.createConnection(props);
-
- // Should occur every time in class loader using existing attributes
- return new EmbeddedConnection(this, serverConn, props, null);
- } catch (ConnectionException e) {
- throw new EmbeddedSQLException(e);
+ } catch (ApplicationInitializationException e) {
+ throw new ConnectionException(e.getCause());
}
- }
+ }
+
/**
* When the DQP is restarted using the admin API, it only shuts it down, it gets
@@ -92,34 +140,159 @@
* @throws ApplicationInitializationException
* @since 4.3
*/
- public void initialize(URL bootstrapURL, Properties props) throws SQLException {
- Injector injector = Guice.createInjector(new EmbeddedGuiceModule(bootstrapURL, props));
- ResourceFinder.setInjector(injector);
- DQPConfigSource configSource = injector.getInstance(DQPConfigSource.class);
-
- // start the DQP
- this.dqp = new DQPCore();
+ public synchronized void initialize(Properties info) throws ApplicationInitializationException {
+ if (this.init) {
+ return;
+ }
+
+ String dqpId = getDQPIdentity(info);
+ info.setProperty(DQPEmbeddedProperties.DQP_IDENTITY, dqpId);
+
+ URL bootstrapURL = null;
+ Properties props = info;
try {
- this.dqp.start(configSource);
- } catch (ApplicationInitializationException e) {
- throw new EmbeddedSQLException(e);
+ bootstrapURL = URLHelper.buildURL(info.getProperty(DQPEmbeddedProperties.BOOTURL));
+ props = PropertiesUtils.loadFromURL(bootstrapURL);
+ props.putAll(info);
+ props = PropertiesUtils.resolveNestedProperties(props);
+ } catch (IOException e) {
+ throw new ApplicationInitializationException(e);
}
+
+ // Create a temporary workspace directory
+ this.workspaceDirectory = createWorkspace(bootstrapURL, props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR), dqpId);
+ props.setProperty(DQPEmbeddedProperties.DQP_WORKSPACE, this.workspaceDirectory);
+
+ this.jmxServer = new JMXUtil(dqpId);
+
+ EmbeddedGuiceModule config = new EmbeddedGuiceModule(bootstrapURL, props);
+ Injector injector = Guice.createInjector(config);
+ ResourceFinder.setInjector(injector);
+ config.setInjector(injector);
+ // start the DQP
+ this.dqp = injector.getInstance(DQPCore.class);
+ this.dqp.start(config);
+
// make the configuration service listen for the connection life-cycle events
// used during VDB delete
ConfigurationService configService = (ConfigurationService)findService(DQPServiceNames.CONFIGURATION_SERVICE);
+ this.clientServices = createClientServices(configService);
+
+ // start socket transport
+ boolean enableSocketTransport = PropertiesUtils.getBooleanProperty(props, DQPEmbeddedProperties.ENABLE_SOCKETS, false);
+ if (enableSocketTransport) {
+ this.socketTransport = new SocketTransport(props, this.clientServices, (SessionServiceInterface)findService(DQPServiceNames.SESSION_SERVICE));
+ this.socketTransport.start();
+ }
+
//in new class loader - all of these should be created lazily and held locally
- this.handler = new LocalTransportHandler(this.dqp);
- this.handler.registerListener(configService.getConnectionListener());
+ listenerList.add(configService.getConnectionListener());
+
this.shutdownThread = new ShutdownWork();
Runtime.getRuntime().addShutdownHook(this.shutdownThread);
this.starttime = System.currentTimeMillis();
+ this.init = true;
DQPEmbeddedPlugin.logInfo("DQPEmbeddedManager.start_dqp", new Object[] {new Date(System.currentTimeMillis()).toString()}); //$NON-NLS-1$
}
- class ShutdownWork extends Thread {
+ private ClientServiceRegistry createClientServices(ConfigurationService configService) {
+ ClientServiceRegistry services = new ClientServiceRegistry();
+
+ SessionServiceInterface sessionService = (SessionServiceInterface)this.dqp.getEnvironment().findService(DQPServiceNames.SESSION_SERVICE);
+ services.registerClientService(ILogon.class, new LogonImpl(sessionService, configService.getClusterName()), com.metamatrix.common.util.LogConstants.CTX_SERVER);
+
+ try {
+ EmbeddedAdmin roleCheckedServerAdmin = wrapAdminService(EmbeddedAdmin.class, (EmbeddedAdmin)getAdminAPI(null));
+ services.registerClientService(EmbeddedAdmin.class, roleCheckedServerAdmin, com.metamatrix.common.util.LogConstants.CTX_ADMIN);
+ } catch (AdminException e) {
+ // ignore; exception is not thrown in this case.
+ }
+
+ services.registerClientService(ClientSideDQP.class, this.dqp, LogConstants.CTX_QUERY_SERVICE);
+
+ return services;
+ }
+
+ /**
+ * Define an identifier for the DQP
+ * @return a JVM level unique identifier
+ */
+ private String getDQPIdentity(Properties props) {
+
+ String processName = props.getProperty(DQPEmbeddedProperties.PROCESSNAME);
+ if (processName != null) {
+ return processName;
+ }
+
+ synchronized (System.class) {
+ String id = System.getProperty(DQPEmbeddedProperties.DQP_IDENTITY, "1"); //$NON-NLS-1$
+ int identity = Integer.parseInt(id);
+ System.setProperty(DQPEmbeddedProperties.DQP_IDENTITY, String.valueOf(identity + 1));
+ id = String.valueOf(identity);
+ return id;
+ }
+ }
+
+ /**
+ * Create the temporary workspace directory for the dqp
+ * @param identity - identity of the dqp
+ * @throws MMSQLException
+ */
+ private String createWorkspace(URL bootstrapURL, String baseDir, String identity) throws ApplicationInitializationException {
+ if (baseDir == null) {
+ baseDir = System.getProperty("java.io.tmpdir")+"/teiid/"; //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ try {
+ baseDir = URLHelper.buildURL(bootstrapURL, baseDir).getPath();
+ } catch (MalformedURLException e) {
+ throw new ApplicationInitializationException(e);
+ }
+ }
+ System.setProperty(DQPEmbeddedProperties.DQP_TMPDIR, baseDir + "/temp"); //$NON-NLS-1$S
+
+ File f = new File(baseDir, identity);
+
+ // If directory already exists then try to delete it; because we may have
+ // failed to delete at end of last run (JVM holds lock on jar files)
+ if (f.exists()) {
+ delete(f);
+ }
+
+ // since we may have cleaned it up now , create the directory again
+ if (!f.exists()) {
+ f.mkdirs();
+ }
+ return f.getAbsolutePath();
+ }
+
+ /**
+ * delete the any directory including sub-trees
+ * @param file
+ */
+ private void delete(File file) {
+ if (file.isDirectory()) {
+ File[] files = file.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ delete(files[i]);
+ } // for
+ }
+
+ // for saftey purpose only delete the jar files
+ if (file.getName().endsWith(".jar")) { //$NON-NLS-1$
+ file.delete();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> T wrapAdminService(Class<T> iface, T impl) {
+ AuthorizationService authService = (AuthorizationService)this.dqp.getEnvironment().findService(DQPServiceNames.AUTHORIZATION_SERVICE);
+ return (T)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {iface}, new AdminAuthorizationInterceptor(authService, impl));
+ }
+
+ class ShutdownWork extends Thread {
ShutdownWork(){
super("embedded-shudown-thread"); //$NON-NLS-1$
}
@@ -169,6 +342,10 @@
private synchronized void shutdown(boolean undoShutdownHook) {
+ if (!isAlive()) {
+ return;
+ }
+
if (undoShutdownHook) {
Runtime.getRuntime().removeShutdownHook(this.shutdownThread);
}
@@ -187,70 +364,62 @@
LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
}
+ // remove any artifacts which are not cleaned-up
+ if (this.workspaceDirectory != null) {
+ File file = new File(this.workspaceDirectory);
+ if (file.exists()) {
+ delete(file);
+ }
+ }
+
this.dqp = null;
- this.handler = null;
-
+ // shutdown the socket transport.
+ if (this.socketTransport != null) {
+ this.socketTransport.stop();
+ this.socketTransport = null;
+ }
+
// shutdown the cache.
ResourceFinder.getCacheFactory().destroy();
shutdownInProgress = false;
+
+ init = false;
}
}
-
- /**
- * Are the connection properties supplied for connection match with those of the
- * DQP
- * @param props
- * @return
- * @since 4.3
- */
- private void checkConnectionProperties(Properties props) throws SQLException {
- String vdbName = props.getProperty(BaseDataSource.VDB_NAME);
- String vdbVersion = props.getProperty(BaseDataSource.VDB_VERSION);
-
- try {
- VDBService service = (VDBService)findService(DQPServiceNames.VDB_SERVICE);
- List<VDBArchive> vdbs = service.getAvailableVDBs();
- // We are looking for the latest version find that now
- if (vdbVersion == null) {
- vdbVersion = findLatestVersion(vdbName, vdbs);
- }
-
- props.setProperty(BaseDataSource.VDB_VERSION, vdbVersion);
+ @Override
+ public Admin getAdminAPI(Properties connectionProperties) throws AdminException {
+
+ InvocationHandler handler = new MixinProxy(new Object[] {
+ new DQPConfigAdminImpl(this),
+ new DQPMonitoringAdminImpl(this),
+ new DQPRuntimeStateAdminImpl(this),
+ new DQPSecurityAdminImpl(this)
+ }) {
- // This below call will load the VDB from configuration into VDB service
- // if not already done so.
- int status = service.getVDB(vdbName, vdbVersion).getStatus();
- if (status != ACTIVE) {
- throw new EmbeddedSQLException(JDBCPlugin.Util.getString("EmbeddedConnectionFactory.vdb_notactive", new Object[] {vdbName, vdbVersion})); //$NON-NLS-1$
- }
- } catch (MetaMatrixComponentException e) {
- throw new EmbeddedSQLException(e, JDBCPlugin.Util.getString("EmbeddedConnectionFactory.vdb_notavailable", new Object[] {vdbName, vdbVersion})); //$NON-NLS-1$
- }
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ // We we perform any DQP functions check if the DQP is still alive
+ if (!isAlive()) {
+ throw new AdminProcessingException(JDBCPlugin.Util.getString("EmbeddedConnection.DQP_shutDown")); //$NON-NLS-1$
+ }
+
+ ClassLoader callingClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // Set the class loader to current class classloader so that the this classe's class loader gets used
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ return super.invoke(proxy, method, args);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(callingClassLoader);
+ }
+ }
+ };
+ return (EmbeddedAdmin) Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[] {EmbeddedAdmin.class}, handler);
}
-
- /**
- * Find the latest version of the VDB available in the deployment.
- * @param vdbName
- * @param vdbs
- * @return
- * @throws EmbeddedSQLException
- * @since 4.3
- */
- String findLatestVersion(String vdbName, List<VDBArchive> vdbs) throws EmbeddedSQLException{
- int latestVersion = 0;
- for (VDBArchive vdb:vdbs) {
- if(vdb.getName().equalsIgnoreCase(vdbName)) {
- // Make sure the VDB Name and version number are the only parts of this vdb key
- latestVersion = Math.max(latestVersion, Integer.parseInt(vdb.getVersion()));
- }
- }
- if(latestVersion != 0) {
- return String.valueOf(latestVersion);
- }
- throw new EmbeddedSQLException(JDBCPlugin.Util.getString("EmbeddedConnectionFactory.vdb_notavailable", vdbName)); //$NON-NLS-1$
- }
-
+
+ public JMXUtil getJMXServer() {
+ return this.jmxServer;
+ }
}
Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,28 +22,50 @@
package com.metamatrix.jdbc;
+import java.net.InetAddress;
import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.jboss.cache.Cache;
import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.internal.process.DQPCore;
import com.google.inject.AbstractModule;
+import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.google.inject.name.Names;
import com.metamatrix.cache.CacheFactory;
import com.metamatrix.cache.jboss.JBossCacheFactory;
+import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.common.application.DQPConfigSource;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.util.NetUtils;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.log.LogListener;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
-import com.metamatrix.dqp.embedded.EmbeddedConfigSource;
+import com.metamatrix.dqp.embedded.services.EmbeddedBufferService;
+import com.metamatrix.dqp.embedded.services.EmbeddedConfigurationService;
+import com.metamatrix.dqp.embedded.services.EmbeddedDataService;
+import com.metamatrix.dqp.embedded.services.EmbeddedMetadataService;
+import com.metamatrix.dqp.embedded.services.EmbeddedTransactionService;
+import com.metamatrix.dqp.embedded.services.EmbeddedVDBService;
+import com.metamatrix.dqp.service.AuthorizationService;
+import com.metamatrix.dqp.service.DQPServiceNames;
+import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
+import com.metamatrix.platform.security.authorization.service.AuthorizationServiceImpl;
+import com.metamatrix.platform.security.membership.service.MembershipServiceImpl;
+import com.metamatrix.platform.security.session.service.SessionServiceImpl;
-public class EmbeddedGuiceModule extends AbstractModule {
+public class EmbeddedGuiceModule extends AbstractModule implements DQPConfigSource{
private Properties props;
private URL bootstrapURL;
+ Injector injector;
public EmbeddedGuiceModule(URL bootstrapURL, Properties props) {
this.bootstrapURL = bootstrapURL;
@@ -57,21 +79,87 @@
bind(URL.class).annotatedWith(Names.named("BootstrapURL")).toInstance(bootstrapURL); //$NON-NLS-1$
bindConstant().annotatedWith(Names.named("HostName")).to("embedded"); //$NON-NLS-1$ //$NON-NLS-2$
- bindConstant().annotatedWith(Names.named("ProcessName")).to(props.getProperty(DQPEmbeddedProperties.DQP_IDENTITY)); //$NON-NLS-1$
- String workspaceDir = props.getProperty(DQPEmbeddedProperties.DQP_WORKSPACE);
+ bindConstant().annotatedWith(Names.named("ProcessName")).to(props.getProperty(DQPEmbeddedProperties.DQP_IDENTITY, "test")); //$NON-NLS-1$ //$NON-NLS-2$
+ String workspaceDir = props.getProperty(DQPEmbeddedProperties.DQP_WORKSPACE, System.getProperty("user.dir")); //$NON-NLS-1$
bindConstant().annotatedWith(Names.named("WorkspaceDir")).to(workspaceDir); //$NON-NLS-1$
bind(Properties.class).annotatedWith(Names.named("DQPProperties")).toInstance(this.props); //$NON-NLS-1$
+ InetAddress address = resolveHostAddress(props.getProperty(DQPEmbeddedProperties.BIND_ADDRESS));
+ bind(InetAddress.class).annotatedWith(Names.named(DQPEmbeddedProperties.HOST_ADDRESS)).toInstance(address);
+ this.props.put(DQPEmbeddedProperties.HOST_ADDRESS, address);
+
bind(Cache.class).toProvider(CacheProvider.class).in(Scopes.SINGLETON);
bind(CacheFactory.class).to(JBossCacheFactory.class).in(Scopes.SINGLETON);
bind(DQPContextCache.class).in(Scopes.SINGLETON);
- bind(DQPConfigSource.class).to(EmbeddedConfigSource.class);
+ bind(DQPCore.class).in(Scopes.SINGLETON);
+ configureServices();
+
// this needs to be removed.
binder().requestStaticInjection(LogManager.class);
}
-
+ private InetAddress resolveHostAddress(String bindAddress) {
+ try {
+ if (bindAddress == null) {
+ return NetUtils.getInstance().getInetAddress();
+ }
+ return NetUtils.resolveHostByName(bindAddress);
+ } catch (UnknownHostException e) {
+ throw new MetaMatrixRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
+ }
+ }
+
+ private void configureServices() {
+ Map<String, Class<? extends ApplicationService>> defaults = getDefaultServiceClasses();
+ for(int i=0; i<DQPServiceNames.ALL_SERVICES.length; i++) {
+ final String serviceName = DQPServiceNames.ALL_SERVICES[i];
+ String className = this.props.getProperty("service."+serviceName+".classname"); //$NON-NLS-1$ //$NON-NLS-2$
+ Class clazz = defaults.get(serviceName);
+ if (clazz != null && className != null) {
+ try {
+ clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+ if (clazz != null) {
+ bind(DQPServiceNames.ALL_SERVICE_CLASSES[i]).to(clazz).in(Scopes.SINGLETON);
+ }
+ }
+ }
+
+ private Map<String, Class<? extends ApplicationService>> getDefaultServiceClasses() {
+ boolean useTxn = PropertiesUtils.getBooleanProperty(props, EmbeddedTransactionService.TRANSACTIONS_ENABLED, true);
+
+ Map<String, Class<? extends ApplicationService>> result = new HashMap<String, Class<? extends ApplicationService>>();
+ result.put(DQPServiceNames.CONFIGURATION_SERVICE, EmbeddedConfigurationService.class);
+ result.put(DQPServiceNames.BUFFER_SERVICE, EmbeddedBufferService.class);
+ result.put(DQPServiceNames.VDB_SERVICE, EmbeddedVDBService.class);
+ result.put(DQPServiceNames.METADATA_SERVICE, EmbeddedMetadataService.class);
+ result.put(DQPServiceNames.DATA_SERVICE, EmbeddedDataService.class);
+ if (useTxn) {
+ result.put(DQPServiceNames.TRANSACTION_SERVICE, EmbeddedTransactionService.class);
+ }
+ result.put(DQPServiceNames.SESSION_SERVICE, SessionServiceImpl.class);
+ result.put(DQPServiceNames.MEMBERSHIP_SERVICE, MembershipServiceImpl.class);
+ result.put(DQPServiceNames.AUTHORIZATION_SERVICE, AuthorizationServiceImpl.class);
+ return result;
+ }
+
+ public void setInjector(Injector injector) {
+ this.injector = injector;
+ }
+
+ @Override
+ public Properties getProperties() {
+ return this.props;
+ }
+
+ @Override
+ public ApplicationService getServiceInstance(Class<? extends ApplicationService> type) {
+ return this.injector.getInstance(type);
+ }
}
Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/Log4JUtil.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/Log4JUtil.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/Log4JUtil.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -107,6 +107,7 @@
contexts.add(ROOT_CONTEXT+com.metamatrix.dqp.util.LogConstants.CTX_EXTENSION_SOURCE);
contexts.add(ROOT_CONTEXT+com.metamatrix.dqp.util.LogConstants.CTX_COMMANDLOGGING);
contexts.add(ROOT_CONTEXT+com.metamatrix.dqp.util.LogConstants.CTX_AUDITLOGGING);
+ contexts.add(ROOT_CONTEXT+com.metamatrix.dqp.util.LogConstants.CTX_QUERY_SERVICE);
contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_CONFIG);
contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_COMMUNICATION);
@@ -115,6 +116,8 @@
contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION);
contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_MEMBERSHIP);
contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION_ADMIN_API);
+ contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_SERVER);
+ contexts.add(ROOT_CONTEXT+com.metamatrix.common.util.LogConstants.CTX_ADMIN);
contexts.add(ROOT_CONTEXT+LogRuntimeMetadataConstants.CTX_RUNTIME_METADATA);
contexts.add("com.arjuna"); //$NON-NLS-1$
Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/LogConfigurationProvider.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/LogConfigurationProvider.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/LogConfigurationProvider.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -39,9 +39,6 @@
@Singleton
class LogConfigurationProvider implements Provider<LogConfiguration> {
- @Inject
- DQPConfigSource configSource;
-
@Override
public LogConfiguration get() {
return new Log4JLogConfiguration();
Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/LogListernerProvider.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/LogListernerProvider.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/LogListernerProvider.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -24,34 +24,32 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Properties;
import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
-import com.metamatrix.common.application.DQPConfigSource;
import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.log.JavaLogWriter;
import com.metamatrix.core.log.LogListener;
-import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
@Singleton
class LogListernerProvider implements Provider<LogListener> {
- @Inject
- DQPConfigSource configSource;
+ @Inject @Named("DQPProperties")
+ Properties props;
@Inject @Named("BootstrapURL")
URL dqpURL;
@Override
public LogListener get() {
- String logFile = configSource.getProperties().getProperty(DQPEmbeddedProperties.DQP_LOGFILE);
- String instanceId = configSource.getProperties().getProperty(DQPEmbeddedProperties.DQP_IDENTITY, "0"); //$NON-NLS-1$
+ String logFile = this.props.getProperty(DQPEmbeddedProperties.DQP_LOGFILE);
+ String instanceId = this.props.getProperty(DQPEmbeddedProperties.DQP_IDENTITY, "0"); //$NON-NLS-1$
// Configure Logging
try {
Modified: trunk/embedded/src/main/java/com/metamatrix/platform/security/authorization/service/AuthorizationServiceImpl.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/platform/security/authorization/service/AuthorizationServiceImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/platform/security/authorization/service/AuthorizationServiceImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -37,6 +37,7 @@
import org.teiid.dqp.internal.process.DQPWorkContext;
import org.xml.sax.SAXException;
+import com.google.inject.Inject;
import com.metamatrix.admin.api.exception.security.InvalidSessionException;
import com.metamatrix.admin.api.exception.security.MetaMatrixSecurityException;
import com.metamatrix.admin.api.server.AdminRoles;
@@ -68,7 +69,6 @@
import com.metamatrix.platform.security.api.MetaMatrixPrincipalName;
import com.metamatrix.platform.security.api.SessionToken;
import com.metamatrix.platform.security.api.StandardAuthorizationActions;
-import com.metamatrix.platform.security.api.service.AuthorizationServicePropertyNames;
import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
import com.metamatrix.platform.security.util.RolePermissionFactory;
import com.metamatrix.platform.util.ErrorMessageKeys;
@@ -95,7 +95,7 @@
/*
* Injected state
*/
- protected MembershipServiceInterface membershipServiceProxy;
+ protected MembershipServiceInterface membershipService;
protected VDBService vdbService;
protected LRUCache<VDBKey, Collection<AuthorizationPolicy>> policyCache = new LRUCache<VDBKey, Collection<AuthorizationPolicy>>();
@@ -106,7 +106,7 @@
* @see com.metamatrix.common.application.ApplicationService#initialize(java.util.Properties)
*/
public void initialize(Properties env) throws ApplicationInitializationException {
- this.useEntitlements = PropertiesUtils.getBooleanProperty(env, AuthorizationServicePropertyNames.DATA_ACCESS_AUTHORIZATION_ENABLED, false);
+ this.useEntitlements = PropertiesUtils.getBooleanProperty(env, ENTITELEMENTS_ENABLED, false);
}
/*
@@ -335,17 +335,19 @@
}
if (realm.getSubRealmName() != null) {
- VDBKey key = new VDBKey(realm.getRealmName(), realm.getSubRealmName());
+ VDBKey key = new VDBKey(realm.getSuperRealmName(), realm.getSubRealmName());
Collection<AuthorizationPolicy> policies = null;
synchronized (this.policyCache) {
policies = this.policyCache.get(key);
if (policies == null) {
try {
- VDBArchive vdb = vdbService.getVDB(realm.getRealmName(), realm.getSubRealmName());
+ VDBArchive vdb = vdbService.getVDB(realm.getSuperRealmName(), realm.getSubRealmName());
if (vdb.getDataRoles() == null) {
policies = Collections.emptyList();
}
- policies = AuthorizationPolicyFactory.buildPolicies(vdb.getName(), vdb.getVersion(), vdb.getDataRoles());
+ else {
+ policies = AuthorizationPolicyFactory.buildPolicies(vdb.getName(), vdb.getVersion(), vdb.getDataRoles());
+ }
} catch (SAXException e) {
throw new AuthorizationMgmtException(e);
} catch (IOException e) {
@@ -381,17 +383,16 @@
*/
private Set<MetaMatrixPrincipalName> getGroupsForPrincipal(MetaMatrixPrincipalName principal)
throws AuthorizationMgmtException, InvalidPrincipalException {
- LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION,
- new Object[] {"getGroupsForPrincipal(", principal, ") - Getting all group memberships."}); //$NON-NLS-1$ //$NON-NLS-2$
+
+ LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION, new Object[] {"getGroupsForPrincipal(", principal, ") - Getting all group memberships."}); //$NON-NLS-1$ //$NON-NLS-2$
// Get the set of all groups this Principal is a member of
Set<MetaMatrixPrincipalName> allPrincipals = new HashSet<MetaMatrixPrincipalName>();
try {
Collection groups = Collections.EMPTY_SET;
- if (principal.getType() == MetaMatrixPrincipal.TYPE_USER ||
- principal.getType() == MetaMatrixPrincipal.TYPE_ADMIN) {
- groups = membershipServiceProxy.getGroupsForUser(principal.getName());
+ if (principal.getType() == MetaMatrixPrincipal.TYPE_USER || principal.getType() == MetaMatrixPrincipal.TYPE_ADMIN) {
+ groups = membershipService.getGroupsForUser(principal.getName());
} else if (principal.getType() == MetaMatrixPrincipal.TYPE_GROUP) {
- MetaMatrixPrincipal groupPrincipal = membershipServiceProxy.getPrincipal(principal);
+ MetaMatrixPrincipal groupPrincipal = membershipService.getPrincipal(principal);
groups = new HashSet();
groups.add(groupPrincipal.getName());
}
@@ -401,8 +402,7 @@
// HACK: Convert ALL member principals to MetaMatrixPrincipalName objs
// since Auth and Memb svcs don't speak the same language.
MetaMatrixPrincipalName member = new MetaMatrixPrincipalName((String) memberItr.next(), MetaMatrixPrincipal.TYPE_GROUP);
- LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION,
- new Object[]{"getGroupsForPrincipal(", principal, ") - Adding membership <", member, ">"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION, new Object[]{"getGroupsForPrincipal(", principal, ") - Adding membership <", member, ">"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
allPrincipals.add(member);
}
// Add original Principal, now that we know he's been authenticated.
@@ -418,14 +418,12 @@
protected boolean isEntitled(String principal) {
try {
- if (membershipServiceProxy.isSuperUser(principal) || !membershipServiceProxy.isSecurityEnabled()) {
- LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION,
- new Object[]{ "Automatically entitling principal", principal}); //$NON-NLS-1$
+ if (membershipService.isSuperUser(principal) || !membershipService.isSecurityEnabled()) {
+ LogManager.logDetail(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION,new Object[]{ "Automatically entitling principal", principal}); //$NON-NLS-1$
return true;
}
} catch (MembershipServiceException e) {
- String msg = PlatformPlugin.Util.getString(ErrorMessageKeys.SEC_AUTHORIZATION_0075);
- LogManager.logError(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION, e, msg);
+ LogManager.logError(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION, e, PlatformPlugin.Util.getString(ErrorMessageKeys.SEC_AUTHORIZATION_0075));
}
return false;
}
@@ -494,17 +492,23 @@
}
}
- public void setMembershipServiceProxy(
- MembershipServiceInterface membershipServiceProxy) {
- this.membershipServiceProxy = membershipServiceProxy;
+ @Inject
+ public void setMembershipService(MembershipServiceInterface membershipService) {
+ this.membershipService = membershipService;
}
public void setUseEntitlements(boolean useEntitlements) {
this.useEntitlements = useEntitlements;
}
+ @Inject
public void setVdbService(VDBService vdbService) {
this.vdbService = vdbService;
}
-
+
+ @Override
+ public boolean isCallerInRole(SessionToken caller, String roleName) throws AuthorizationMgmtException {
+ LogManager.logTrace(com.metamatrix.common.util.LogConstants.CTX_AUTHORIZATION, new Object[]{"isCallerInRole(", caller, roleName, ")"}); //$NON-NLS-1$ //$NON-NLS-2$
+ return hasPolicy(caller, RolePermissionFactory.getRealm(), roleName);
+ }
}
Modified: trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/service/MembershipServiceImpl.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/service/MembershipServiceImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/service/MembershipServiceImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -24,7 +24,9 @@
import java.io.IOException;
import java.io.Serializable;
+import java.net.InetAddress;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -38,6 +40,8 @@
import org.teiid.dqp.internal.process.DQPWorkContext;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
import com.metamatrix.admin.api.exception.security.MetaMatrixSecurityException;
import com.metamatrix.api.exception.security.InvalidPrincipalException;
import com.metamatrix.api.exception.security.InvalidUserException;
@@ -47,14 +51,15 @@
import com.metamatrix.common.application.ApplicationEnvironment;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
-import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.api.AuthenticationProviderType;
import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.common.util.LogConstants;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.util.crypto.CryptoException;
import com.metamatrix.common.util.crypto.CryptoUtil;
import com.metamatrix.core.util.StringUtil;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.platform.PlatformPlugin;
import com.metamatrix.platform.security.api.BasicMetaMatrixPrincipal;
import com.metamatrix.platform.security.api.Credentials;
@@ -114,15 +119,19 @@
private boolean isSecurityEnabled = true;
private List<MembershipDomainHolder> domains = new ArrayList<MembershipDomainHolder>();
+ private URL dqpURL;
+ private InetAddress hostAddress;
- public MembershipServiceImpl() {
- super();
+ @Inject
+ public MembershipServiceImpl(@Named("BootstrapURL") URL dqpURL, @Named(DQPEmbeddedProperties.HOST_ADDRESS) InetAddress hostAddress) {
+ this.dqpURL = dqpURL;
+ this.hostAddress = hostAddress;
}
// -----------------------------------------------------------------------------------
// S E R V I C E - R E L A T E D M E T H O D S
// -----------------------------------------------------------------------------------
-
+
/**
* Perform initialization and commence processing. This method is called only once.
* <p>Note: In order to perform the chaining of membership domains, this method assumes
@@ -132,8 +141,14 @@
* @throws ApplicationInitializationException
*/
@Override
- public void initialize(Properties env)
- throws ApplicationInitializationException {
+ public void initialize(Properties env) throws ApplicationInitializationException {
+
+ isSecurityEnabled = Boolean.valueOf(env.getProperty(SECURITY_ENABLED)).booleanValue();
+ LogManager.logDetail(LogConstants.CTX_MEMBERSHIP, "Security Enabled: " + isSecurityEnabled); //$NON-NLS-1$
+
+ if (!isSecurityEnabled) {
+ return;
+ }
adminUsername = env.getProperty(ADMIN_USERNAME, DEFAULT_ADMIN_USERNAME);
@@ -147,15 +162,14 @@
this.allowedAddresses = Pattern.compile(property);
}
- isSecurityEnabled = Boolean.valueOf(env.getProperty(SECURITY_ENABLED)).booleanValue();
- LogManager.logDetail(LogConstants.CTX_MEMBERSHIP, "Security Enabled: " + isSecurityEnabled); //$NON-NLS-1$
-
- try {
- //TODO: my caller should have already decrypted this for me
- adminCredentials = CryptoUtil.stringDecrypt(adminCredentials);
- } catch (CryptoException err) {
- LogManager.logCritical(LogConstants.CTX_MEMBERSHIP, err, PlatformPlugin.Util.getString("MembershipServiceImpl.Root_password_decryption_failed")); //$NON-NLS-1$
- throw new ApplicationInitializationException(err);
+ if (CryptoUtil.isValueEncrypted(adminCredentials)) {
+ try {
+ //TODO: my caller should have already decrypted this for me
+ adminCredentials = CryptoUtil.stringDecrypt(adminCredentials);
+ } catch (CryptoException err) {
+ LogManager.logCritical(LogConstants.CTX_MEMBERSHIP, err, PlatformPlugin.Util.getString("MembershipServiceImpl.Root_password_decryption_failed")); //$NON-NLS-1$
+ throw new ApplicationInitializationException(err);
+ }
}
String domainNameOrder = env.getProperty(MembershipServiceInterface.DOMAIN_ORDER);
@@ -216,13 +230,17 @@
properties.setProperty(DOMAIN_NAME, domainName);
- String propsString = properties.getProperty(DOMAIN_PROPERTIES);
+ String propsString = properties.getProperty(DOMAIN_PROPERTIES);
if (propsString != null) {
- Properties customProps = PropertiesUtils.loadFromURL(propsString);
+ URL url = URLHelper.buildURL(this.dqpURL, propsString);
+ Properties customProps = PropertiesUtils.loadFromURL(url);
properties.putAll(customProps);
+
+ // Using this URL the Membership providers can further define and files that are in relative context to this file
+ properties.put(DOMAIN_PROPERTIES, url);
}
-
+
domain.initialize(properties);
return domain;
@@ -295,7 +313,7 @@
LogManager.logWarning(LogConstants.CTX_MEMBERSHIP, PlatformPlugin.Util.getString("MembershipServiceImpl.unknown_host")); //$NON-NLS-1$
return new FailedAuthenticationToken();
}
- if (!allowedAddresses.matcher(address).matches() || address.equals(CurrentConfiguration.getInstance().getHostAddress().getHostAddress())) {
+ if (!allowedAddresses.matcher(address).matches() && !address.equals(this.hostAddress.getHostAddress())) {
LogManager.logWarning(LogConstants.CTX_MEMBERSHIP, PlatformPlugin.Util.getString("MembershipServiceImpl.invalid_host", address, allowedAddresses.pattern())); //$NON-NLS-1$
return new FailedAuthenticationToken();
}
Modified: trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/spi/file/FileMembershipDomain.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/spi/file/FileMembershipDomain.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/platform/security/membership/spi/file/FileMembershipDomain.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -36,8 +37,10 @@
import com.metamatrix.api.exception.security.InvalidUserException;
import com.metamatrix.api.exception.security.LogonException;
import com.metamatrix.api.exception.security.UnsupportedCredentialException;
+import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.platform.security.api.Credentials;
+import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
import com.metamatrix.platform.security.api.service.SuccessfulAuthenticationToken;
import com.metamatrix.platform.security.membership.spi.MembershipDomain;
import com.metamatrix.platform.security.membership.spi.MembershipSourceException;
@@ -71,14 +74,14 @@
throw new MembershipSourceException("Required property " +USERS_FILE+ " was missing."); //$NON-NLS-1$ //$NON-NLS-2$
}
- users = loadFile(userFile);
+ users = loadFile(env, userFile);
if (groupFile == null) {
throw new MembershipSourceException("Required property " +GROUPS_FILE+ " was missing."); //$NON-NLS-1$ //$NON-NLS-2$
}
groups.clear();
- groups.putAll(loadFile(groupFile));
+ groups.putAll(loadFile(env, groupFile));
userGroups.clear();
for (Iterator i = groups.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry)i.next();
@@ -98,9 +101,10 @@
}
}
- private Properties loadFile(String file) throws MembershipSourceException {
+ private Properties loadFile(Properties env, String file) throws MembershipSourceException {
try {
- return PropertiesUtils.loadFromURL(file);
+ URL baseURL = (URL)env.get(MembershipServiceInterface.DOMAIN_PROPERTIES);
+ return PropertiesUtils.loadFromURL(URLHelper.buildURL(baseURL, file));
} catch (MalformedURLException e) {
throw new MembershipSourceException(e, "Could not load file"); //$NON-NLS-1$
} catch (IOException e) {
Modified: trunk/embedded/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -35,6 +35,8 @@
import org.teiid.dqp.internal.process.DQPCore;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
import com.metamatrix.admin.api.exception.security.InvalidSessionException;
import com.metamatrix.admin.api.exception.security.MetaMatrixSecurityException;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -49,6 +51,7 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.util.LogConstants;
import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.dqp.service.VDBService;
import com.metamatrix.metadata.runtime.exception.VirtualDatabaseDoesNotExistException;
import com.metamatrix.metadata.runtime.exception.VirtualDatabaseException;
@@ -295,7 +298,8 @@
return info;
}
- void setMembershipService(MembershipServiceInterface membershipService) {
+ @Inject
+ public void setMembershipService(MembershipServiceInterface membershipService) {
this.membershipService = membershipService;
}
@@ -315,14 +319,15 @@
this.sessionTimeLimit = sessionTimeLimit;
}
+ @Inject
public void setDqpCore(DQPCore dqpCore) {
this.dqpCore = dqpCore;
}
@Override
- public void initialize(Properties props)
- throws ApplicationInitializationException {
-
+ public void initialize(Properties props) throws ApplicationInitializationException {
+ this.sessionMaxLimit = Long.parseLong(props.getProperty(MAX_SESSIONS, DEFAULT_MAX_SESSIONS));
+ this.sessionTimeLimit = Long.parseLong(props.getProperty(SESSION_TIMEOUT, DEFAULT_SESSION_TIMEOUT));
}
@Override
@@ -342,6 +347,7 @@
this.sessionMonitor.cancel();
}
+ @Inject
public void setVdbService(VDBService vdbService) {
this.vdbService = vdbService;
}
Added: trunk/embedded/src/main/java/org/teiid/Server.java
===================================================================
--- trunk/embedded/src/main/java/org/teiid/Server.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/Server.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.net.InetAddress;
+import java.nio.channels.FileChannel;
+import java.util.Properties;
+
+import com.metamatrix.common.application.exception.ApplicationInitializationException;
+import com.metamatrix.common.util.JMXUtil.FailedToRegisterException;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
+import com.metamatrix.jdbc.EmbeddedConnectionFactoryImpl;
+
+public class Server implements ServerMBean{
+
+ private Properties props;
+ private EmbeddedConnectionFactoryImpl engine;
+
+ public Server(Properties props) {
+ this.props = props;
+ }
+
+ private void start() {
+ try {
+ // start the engine.
+ this.engine = new EmbeddedConnectionFactoryImpl();
+ this.engine.initialize(this.props);
+
+ this.engine.getJMXServer().register(TYPE, NAME, this);
+
+ } catch (ApplicationInitializationException e) {
+ throw new MetaMatrixRuntimeException(e);
+ } catch (FailedToRegisterException e) {
+ throw new MetaMatrixRuntimeException(e.getCause());
+ }
+ }
+
+ private void stopS() {
+ if (engine.isAlive()) {
+ engine.shutdown();
+ }
+
+ try {
+ this.engine.getJMXServer().unregister(TYPE, NAME);
+ } catch (FailedToRegisterException e) {
+ // ignore
+ }
+ }
+
+ public static boolean duplicateProcess(Properties props) {
+ try {
+ String parent = new File(new File(props.getProperty(DQPEmbeddedProperties.BOOTURL)).getParent(), props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR)).getCanonicalPath();
+ File f = new File(parent, "teiid.pid"); //$NON-NLS-1$
+ FileChannel channel = new RandomAccessFile(f, "rw").getChannel(); //$NON-NLS-1$
+ return (channel.tryLock() == null);
+ } catch (IOException e) {
+ // ignore
+ }
+ return true;
+ }
+
+
+ private static Properties loadConfiguration(String configFile) {
+ File f = new File (configFile);
+ if (!f.exists()) {
+ System.out.println("Missing the bootstrap properties file, failed to start"); //$NON-NLS-1$
+ System.exit(-3);
+ }
+
+ Properties props = null;
+ try {
+ FileReader bootProperties = new FileReader(f);
+ props = new Properties();
+ props.load(bootProperties);
+
+ // enable socket communication by default.
+ props.setProperty(DQPEmbeddedProperties.ENABLE_SOCKETS, Boolean.TRUE.toString());
+ props.setProperty(DQPEmbeddedProperties.BOOTURL, f.getCanonicalPath());
+
+ } catch (IOException e) {
+ System.out.println("Failed to load bootstrap properties file."); //$NON-NLS-1$
+ e.printStackTrace();
+ System.exit(-3);
+ }
+ return props;
+ }
+
+ @Override
+ public boolean isAlive() {
+ return engine.isAlive();
+ }
+
+ @Override
+ public void shutdown() {
+ new Thread(){
+ public void run(){
+ System.out.println("Server being shutdown..."); //$NON-NLS-1$
+ stopS();
+ }
+ }.start();
+ }
+
+ @Override
+ public void halt() {
+ new Thread() {
+ public void run() {
+ System.err.println("Killing the Teiid Server now!"); //$NON-NLS-1$
+ Runtime.getRuntime().halt(-4);
+ }
+ }.start();
+ }
+ /**
+ * Start the Server Mode
+ * @param args
+ */
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.out.println("Usage:Server <boot-properties-file>"); //$NON-NLS-1$
+ System.exit(-1);
+ }
+
+ long startTime = System.currentTimeMillis();
+
+ // load configuration
+ Properties props = loadConfiguration(args[0]);
+
+ // check for duplicate process
+ if (duplicateProcess(props)) {
+ System.out.println("There is already another Server process running! Failed to start"); //$NON-NLS-1$
+ System.exit(-2);
+ }
+
+ // load the server
+ Server s = new Server(props);
+ s.start();
+
+ String port = props.getProperty(DQPEmbeddedProperties.SERVER_PORT);
+ long time = System.currentTimeMillis() - startTime;
+
+ System.out.println("Teiid Server started on port = "+port + "in "+time/1000+" Secs"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ // wait.
+ while(s.isAlive()) {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+
+ // if for some reason engine is still alive kill it.
+ if (s.isAlive()) {
+ s.stopS();
+ }
+ }
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/Server.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/embedded/src/main/java/org/teiid/ServerMBean.java
===================================================================
--- trunk/embedded/src/main/java/org/teiid/ServerMBean.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/ServerMBean.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid;
+
+import javax.management.ObjectName;
+
+import com.metamatrix.common.util.JMXUtil;
+
+public interface ServerMBean {
+ public static final String NAME = "Server"; //$NON-NLS-1$
+ public static final JMXUtil.MBeanType TYPE = JMXUtil.MBeanType.SERVER;
+
+ boolean isAlive();
+
+ void shutdown();
+
+ void halt();
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/ServerMBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/embedded/src/main/java/org/teiid/Shutdown.java
===================================================================
--- trunk/embedded/src/main/java/org/teiid/Shutdown.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/Shutdown.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,101 @@
+package org.teiid;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import com.metamatrix.common.util.JMXUtil;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
+
+public class Shutdown {
+
+ public static void main(String[] args) throws Exception {
+ if (args.length < 2) {
+ System.out.println("Usage:Shutdown <boot-properties-file> <jmxPort>"); //$NON-NLS-1$
+ System.exit(-1);
+ }
+
+ Properties props = loadConfiguration(args[0]);
+
+ JMXUtil jmx = new JMXUtil(props.getProperty(DQPEmbeddedProperties.PROCESSNAME));
+
+ JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:"+args[1]+"/jmxrmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
+ MBeanServerConnection mbsc = connector.getMBeanServerConnection();
+
+ ServerProxyHandler handler = new ServerProxyHandler(mbsc, jmx.buildName(ServerMBean.TYPE, ServerMBean.NAME));
+ Class<?>[] ifaces = { ServerMBean.class };
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ ServerMBean server = (ServerMBean) Proxy.newProxyInstance(tcl, ifaces,handler);
+ server.shutdown();
+ }
+
+ private static Properties loadConfiguration(String configFile) {
+ File f = new File (configFile);
+ if (!f.exists()) {
+ System.out.println("Missing the bootstrap properties file, failed to start"); //$NON-NLS-1$
+ System.exit(-3);
+ }
+
+ Properties props = null;
+ try {
+ FileReader bootProperties = new FileReader(f);
+ props = new Properties();
+ props.load(bootProperties);
+
+ // enable socket communication by default.
+ props.setProperty(DQPEmbeddedProperties.ENABLE_SOCKETS, Boolean.TRUE.toString());
+ props.setProperty(DQPEmbeddedProperties.BOOTURL, f.getCanonicalPath());
+
+ } catch (IOException e) {
+ System.out.println("Failed to load bootstrap properties file."); //$NON-NLS-1$
+ e.printStackTrace();
+ System.exit(-3);
+ }
+ return props;
+ }
+
+ /**
+ * Taken from JBoss AS Shutdown.java class.
+ */
+ private static class ServerProxyHandler implements InvocationHandler {
+ ObjectName serverName;
+ MBeanServerConnection server;
+
+ ServerProxyHandler(MBeanServerConnection server, ObjectName serverName) {
+ this.server = server;
+ this.serverName = serverName;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ String methodName = method.getName();
+ Class[] sigTypes = method.getParameterTypes();
+ ArrayList sigStrings = new ArrayList();
+ for (int s = 0; s < sigTypes.length; s++) {
+ sigStrings.add(sigTypes[s].getName());
+ }
+ String[] sig = new String[sigTypes.length];
+ sigStrings.toArray(sig);
+ Object value = null;
+ try {
+ value = server.invoke(serverName, methodName, args, sig);
+ } catch (UndeclaredThrowableException e) {
+ throw e.getUndeclaredThrowable();
+ }
+ return value;
+ }
+ }
+
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/Shutdown.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/embedded/src/main/java/org/teiid/transport/AdminAuthorizationInterceptor.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/AdminAuthorizationInterceptor.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/AdminAuthorizationInterceptor.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/AdminAuthorizationInterceptor.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.admin.RolesAllowed;
+import com.metamatrix.admin.api.server.AdminRoles;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.security.AuthorizationException;
+import com.metamatrix.client.ExceptionUtil;
+import com.metamatrix.common.comm.platform.CommPlatformPlugin;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.log.MessageLevel;
+import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.dqp.service.AuditMessage;
+import com.metamatrix.dqp.service.AuthorizationService;
+import com.metamatrix.dqp.util.LogConstants;
+import com.metamatrix.platform.security.api.SessionToken;
+
+/**
+ * Call authorization service to make sure the current admin user has the
+ * proper admin role(s) to perform the method.
+ */
+public class AdminAuthorizationInterceptor implements InvocationHandler {
+
+ private final Object service;
+ private AuthorizationService authAdmin;
+
+
+ /**
+ * Ctor.
+ * @param securityContextFactory
+ * @param authorizationService
+ * @param methodNames
+ * @since 4.3
+ */
+ public AdminAuthorizationInterceptor(AuthorizationService authorizationService, Object service) {
+ ArgCheck.isNotNull(authorizationService);
+ this.authAdmin = authorizationService;
+ this.service = service;
+ }
+
+ /**
+ *
+ * @param invocation
+ * @param securityContext
+ * @throws AuthorizationException
+ * @throws MetaMatrixProcessingException
+ * @since 4.3
+ */
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ SessionToken adminToken = DQPWorkContext.getWorkContext().getSessionToken();
+
+ Method serviceMethod = service.getClass().getMethod(method.getName(), method.getParameterTypes());
+ RolesAllowed allowed = serviceMethod.getAnnotation(RolesAllowed.class);
+ if (allowed == null) {
+ allowed = method.getAnnotation(RolesAllowed.class);
+ if (allowed == null) {
+ allowed = serviceMethod.getDeclaringClass().getAnnotation(RolesAllowed.class);
+ if (allowed == null) {
+ allowed = method.getDeclaringClass().getAnnotation(RolesAllowed.class);
+ }
+ }
+ }
+ if (allowed == null || allowed.value() == null) {
+ throw new MetaMatrixRuntimeException("Could not determine roles allowed for admin method"); //$NON-NLS-1$
+ }
+
+ boolean authorized = false;
+ AuditMessage msg = new AuditMessage(LogConstants.CTX_ADMIN_API, Arrays.toString(allowed.value())+"-request", adminToken.getUsername(), new Object[]{method.getName()}); //$NON-NLS-1$
+ LogManager.log(MessageLevel.INFO, LogConstants.CTX_AUDITLOGGING, msg);
+
+ for (int i = 0; i < allowed.value().length; i++) {
+ String requiredRoleName = allowed.value()[i];
+ if (AdminRoles.RoleName.ANONYMOUS.equalsIgnoreCase(requiredRoleName)) {
+ authorized = true;
+ break;
+ }
+
+ if (authAdmin.isCallerInRole(adminToken, requiredRoleName)) {
+ authorized = true;
+ break;
+ }
+ }
+ if (!authorized) {
+ msg = new AuditMessage(LogConstants.CTX_ADMIN_API, Arrays.toString(allowed.value())+"-denied", adminToken.getUsername(), new Object[]{method.getName()}); //$NON-NLS-1$
+ LogManager.log(MessageLevel.INFO, LogConstants.CTX_AUDITLOGGING, msg);
+
+ Object[] msgParts = buildAuditMessage(adminToken, Arrays.toString(allowed.value()), method);
+ String errMsg = CommPlatformPlugin.Util.getString("AdminAuthorizationInterceptor.Admin_not_authorized", msgParts); //$NON-NLS-1$
+ throw ExceptionUtil.convertException(method, new AuthorizationException(errMsg));
+ }
+ try {
+ return method.invoke(service, args);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ }
+ }
+
+ /**
+ * Builds an audit msg using given values including method signature string from given invocation using method
+ * name and argument values.
+ * @param securityContext
+ * @param adminToken
+ * @param requiredRoleName
+ * @param invocation
+ * @return
+ * @since 5.0
+ */
+ private Object[] buildAuditMessage(SessionToken adminToken, String requiredRoleName, Method invocation) {
+ return new Object[] {adminToken.getUsername(), adminToken.getSessionID().toString(), requiredRoleName, invocation.getName()};
+ }
+
+}
Copied: trunk/embedded/src/main/java/org/teiid/transport/ChannelListener.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/ChannelListener.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/ChannelListener.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/ChannelListener.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.platform.socket.ObjectChannel;
+
+public interface ChannelListener {
+
+ public interface ChannelListenerFactory {
+ ChannelListener createChannelListener(ObjectChannel channel);
+ }
+
+ void receivedMessage(Object msg) throws CommunicationException;
+
+ void exceptionOccurred(Throwable t);
+
+ void onConnection() throws CommunicationException;
+}
\ No newline at end of file
Property changes on: trunk/embedded/src/main/java/org/teiid/transport/ChannelListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/embedded/src/main/java/org/teiid/transport/ClientInstance.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ClientInstance.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/ClientInstance.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/ClientInstance.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.io.Serializable;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.common.comm.api.Message;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.util.crypto.Cryptor;
+
+/**
+ * Represents a ClientConnection from the server's point of view. This interface
+ * can be used by a ServerListener implementation to manage the incoming
+ * client connections, retrieve information about a particular connection,
+ * and send a message to a particular connection in the asynchronous message scenario.
+ */
+public interface ClientInstance {
+
+ /**
+ * Send a message to this particular client using the asynch message key.
+ * @param message The message to send
+ * @param messageKey The key sent with the asynch query
+ * @throws CommunicationException If an error occurs during the send
+ */
+ void send(Message message, Serializable messageKey);
+
+ /**
+ * Shutdown the server's connection to the client.
+ * @throws CommunicationException If an error occurs during the shutdown
+ */
+ void shutdown() throws CommunicationException;
+
+ Cryptor getCryptor();
+
+ DQPWorkContext getWorkContext();
+}
Copied: trunk/embedded/src/main/java/org/teiid/transport/LocalServerConnection.java (from rev 1067, trunk/embedded/src/main/java/com/metamatrix/jdbc/transport/LocalServerConnection.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/LocalServerConnection.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/LocalServerConnection.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Properties;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.security.LogonException;
+import com.metamatrix.client.ExceptionUtil;
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.api.ServerConnection;
+import com.metamatrix.common.comm.api.ServerConnectionListener;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.exception.ConnectionException;
+import com.metamatrix.common.comm.platform.CommPlatformPlugin;
+import com.metamatrix.dqp.client.ClientSideDQP;
+import com.metamatrix.jdbc.JDBCPlugin;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.LogonResult;
+import com.metamatrix.platform.security.api.SessionToken;
+
+public class LocalServerConnection implements ServerConnection {
+
+ private final LogonResult result;
+ private boolean shutdown;
+ private DQPWorkContext workContext;
+ private ServerConnectionListener listener;
+ private ClassLoader classLoader;
+ ClientServiceRegistry clientServices;
+
+
+ public LocalServerConnection(Properties connectionProperties, ClientServiceRegistry clientServices, ServerConnectionListener listener) throws CommunicationException, ConnectionException{
+
+ this.clientServices = clientServices;
+
+ //Initialize the workContext
+ workContext = new DQPWorkContext();
+ DQPWorkContext.setWorkContext(workContext);
+
+ this.result = authenticate(connectionProperties);
+
+ this.listener = listener;
+
+ if (this.listener != null) {
+ this.listener.connectionAdded(this);
+ }
+
+ this.classLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ public synchronized LogonResult authenticate(Properties connProps) throws ConnectionException, CommunicationException {
+ try {
+ LogonResult logonResult = getService(ILogon.class).logon(connProps);
+ return logonResult;
+ } catch (LogonException e) {
+ // Propagate the original message as it contains the message we want
+ // to give to the user
+ throw new ConnectionException(e, e.getMessage());
+ } catch (MetaMatrixComponentException e) {
+ if (e.getCause() instanceof CommunicationException) {
+ throw (CommunicationException)e.getCause();
+ }
+ throw new CommunicationException(e, CommPlatformPlugin.Util.getString("PlatformServerConnectionFactory.Unable_to_find_a_component_used_in_logging_on_to_MetaMatrix")); //$NON-NLS-1$
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public <T> T getService(final Class<T> iface) {
+
+ return (T) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {iface}, new InvocationHandler() {
+
+ public Object invoke(Object arg0, Method arg1, Object[] arg2)
+ throws Throwable {
+ if (!isOpen()) {
+ throw ExceptionUtil.convertException(arg1, new MetaMatrixComponentException(JDBCPlugin.Util.getString("LocalTransportHandler.session_inactive"))); //$NON-NLS-1$
+ }
+ ClassLoader current = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ DQPWorkContext.setWorkContext(workContext);
+ try {
+ return arg1.invoke(clientServices.getClientService(iface), arg2);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ } finally {
+ Thread.currentThread().setContextClassLoader(current);
+ }
+ }
+ });
+ }
+
+ public boolean isOpen() {
+ return !shutdown;
+ }
+
+ public void shutdown() {
+ if (shutdown) {
+ return;
+ }
+ if (this.listener != null) {
+ this.listener.connectionRemoved(this);
+ }
+ this.shutdown = true;
+ }
+
+ public LogonResult getLogonResult() {
+ return result;
+ }
+
+ @Override
+ public boolean isSameInstance(ServerConnection conn) throws CommunicationException {
+ return (conn instanceof LocalServerConnection);
+ }
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/transport/LocalServerConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/embedded/src/main/java/org/teiid/transport/LogonImpl.java (from rev 1068, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/LogonImpl.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/LogonImpl.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/LogonImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.CredentialMap;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.admin.api.exception.security.InvalidSessionException;
+import com.metamatrix.api.exception.ComponentNotFoundException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.security.LogonException;
+import com.metamatrix.api.exception.security.MetaMatrixAuthenticationException;
+import com.metamatrix.api.exception.security.SessionServiceException;
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.util.LogConstants;
+import com.metamatrix.dqp.client.ResultsFuture;
+import com.metamatrix.jdbc.api.ConnectionProperties;
+import com.metamatrix.platform.PlatformPlugin;
+import com.metamatrix.platform.security.api.Credentials;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.LogonResult;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
+import com.metamatrix.platform.security.api.MetaMatrixSessionInfo;
+import com.metamatrix.platform.security.api.SessionToken;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+import com.metamatrix.platform.util.ProductInfoConstants;
+
+public class LogonImpl implements ILogon {
+
+ private SessionServiceInterface service;
+ private String clusterName;
+
+ public LogonImpl(SessionServiceInterface service, String clusterName) {
+ this.service = service;
+ this.clusterName = clusterName;
+ }
+
+ public LogonResult logon(Properties connProps) throws LogonException,
+ ComponentNotFoundException {
+
+ String applicationName = connProps.getProperty(MMURL.CONNECTION.APP_NAME);
+ // user may be null if using trustedToken to log on
+ String user = connProps.getProperty(MMURL.CONNECTION.USER_NAME);
+ // password may be null if using trustedToken to log on
+ String password = connProps.getProperty(MMURL.CONNECTION.PASSWORD);
+ Credentials credential = null;
+ if (password != null) {
+ credential = new Credentials(password.toCharArray());
+ }
+
+ if(connProps.containsKey(ConnectionProperties.PROP_CREDENTIALS)) {
+ handleCredentials(connProps, user, password);
+ }
+
+ Object payload = connProps.get(MMURL.CONNECTION.CLIENT_TOKEN_PROP);
+
+ try {
+ MetaMatrixSessionInfo sessionInfo = service.createSession(user,
+ credential, (Serializable) payload, applicationName,
+ connProps);
+ // logon
+ MetaMatrixSessionID sessionID = updateDQPContext(sessionInfo);
+ LogManager.logDetail(LogConstants.CTX_SESSION, new Object[] {
+ "Logon successful for \"", user, "\" - created SessionID \"", "" + sessionID, "\"" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return new LogonResult(sessionInfo.getSessionToken(), sessionInfo.getProductInfo(), clusterName);
+ } catch (MetaMatrixAuthenticationException e) {
+ throw new LogonException(e, e.getMessage());
+ } catch (SessionServiceException e) {
+ throw new LogonException(e, e.getMessage());
+ }
+ }
+
+ private void handleCredentials(Properties connProps, String user, String password) throws LogonException {
+
+ // Check if both credentials AND session token are used - if so, this is an error
+ if(connProps.containsKey(ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD)) {
+ throw new LogonException(PlatformPlugin.Util.getString("LogonImpl.Invalid_use_of_credentials_and_token")); //$NON-NLS-1$
+ }
+
+ // Parse credentials and store CredentialMap as session token
+ try {
+ String credentials = connProps.getProperty(ConnectionProperties.PROP_CREDENTIALS);
+ CredentialMap credentialMap = null;
+ boolean defaultToLogon = false;
+ if(credentials.startsWith(ConnectionProperties.DEFAULT_TO_LOGON)) {
+ defaultToLogon = true;
+ }
+ int parenIndex = credentials.indexOf("("); //$NON-NLS-1$
+ if(parenIndex >= 0) {
+ credentialMap = CredentialMap.parseCredentials(credentials.substring(parenIndex));
+ } else {
+ credentialMap = new CredentialMap();
+ }
+ if(defaultToLogon) {
+ credentialMap.setDefaultCredentialMode(CredentialMap.MODE_USE_DEFAULTS_GLOBALLY);
+ Map<String, String> defaultCredentials = new HashMap<String, String>();
+ defaultCredentials.put(CredentialMap.USER_KEYWORD, user);
+ defaultCredentials.put(CredentialMap.PASSWORD_KEYWORD, password);
+ credentialMap.setDefaultCredentials(defaultCredentials);
+ } else {
+ credentialMap.setDefaultCredentialMode(CredentialMap.MODE_IGNORE_DEFAULTS);
+ }
+ connProps.put(ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD, credentialMap);
+ } catch(ConnectorException e) {
+ throw new LogonException(e.getMessage());
+ }
+
+ // Remove credentials from info properties
+ connProps.remove(ConnectionProperties.PROP_CREDENTIALS);
+ }
+
+ private MetaMatrixSessionID updateDQPContext(MetaMatrixSessionInfo sessionInfo) {
+ MetaMatrixSessionID sessionID = sessionInfo.getSessionID();
+ DQPWorkContext workContext = DQPWorkContext.getWorkContext();
+ workContext.setSessionToken(sessionInfo.getSessionToken());
+ workContext.setAppName(sessionInfo.getApplicationName());
+ workContext.setTrustedPayload(sessionInfo.getTrustedToken());
+ workContext.setVdbName(sessionInfo.getProductInfo(ProductInfoConstants.VIRTUAL_DB));
+ workContext.setVdbVersion(sessionInfo.getProductInfo(ProductInfoConstants.VDB_VERSION));
+ return sessionID;
+ }
+
+ public ResultsFuture<?> logoff() throws InvalidSessionException, MetaMatrixComponentException {
+ try {
+ this.service.closeSession(DQPWorkContext.getWorkContext().getSessionId());
+ } catch (SessionServiceException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ return null;
+ }
+
+ public ResultsFuture<?> ping() throws InvalidSessionException,MetaMatrixComponentException {
+ this.service.pingServer(DQPWorkContext.getWorkContext().getSessionId());
+ return null;
+ }
+
+ @Override
+ public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, MetaMatrixComponentException {
+ MetaMatrixSessionInfo sessionInfo;
+ try {
+ sessionInfo = this.service.validateSession(sessionId.getSessionID());
+ } catch (SessionServiceException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+
+ if (!sessionInfo.getSessionToken().equals(sessionInfo.getSessionToken())) {
+ throw new InvalidSessionException();
+ }
+ this.updateDQPContext(sessionInfo);
+ }
+
+}
Copied: trunk/embedded/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SSLAwareChannelHandler.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/**
+ *
+ */
+package org.teiid.transport;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.net.ssl.SSLEngine;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.DefaultChannelPipeline;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.handler.codec.serialization.ObjectDecoder;
+import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
+import org.jboss.netty.handler.ssl.SslHandler;
+
+import com.metamatrix.common.comm.exception.SingleInstanceCommunicationException;
+import com.metamatrix.common.comm.platform.CommPlatformPlugin;
+import com.metamatrix.common.comm.platform.socket.ObjectChannel;
+
+/**
+ * Main class for creating Netty Nio Channels
+ */
+
+(a)ChannelPipelineCoverage(ChannelPipelineCoverage.ALL)
+public class SSLAwareChannelHandler extends SimpleChannelHandler implements ChannelPipelineFactory {
+
+ public class ObjectChannelImpl implements ObjectChannel {
+ private final Channel channel;
+
+ public ObjectChannelImpl(Channel channel) {
+ this.channel = channel;
+ }
+
+ public void close() {
+ channel.close();
+ }
+
+ public boolean isOpen() {
+ return channel.isOpen();
+ }
+
+ public SocketAddress getRemoteAddress() {
+ return channel.getRemoteAddress();
+ }
+
+ @Override
+ public Object read() throws IOException,
+ ClassNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Future<?> write(Object msg) {
+ final ChannelFuture future = channel.write(msg);
+ future.addListener(completionListener);
+ return new Future<Void>() {
+
+ @Override
+ public boolean cancel(boolean arg0) {
+ return future.cancel();
+ }
+
+ @Override
+ public Void get() throws InterruptedException,
+ ExecutionException {
+ future.await();
+ if (!future.isSuccess()) {
+ throw new ExecutionException(future.getCause());
+ }
+ return null;
+ }
+
+ @Override
+ public Void get(long arg0, TimeUnit arg1)
+ throws InterruptedException, ExecutionException,
+ TimeoutException {
+ if (future.await(arg0, arg1)) {
+ if (!future.isSuccess()) {
+ throw new ExecutionException(future.getCause());
+ }
+ return null;
+ }
+ throw new TimeoutException();
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return future.isCancelled();
+ }
+
+ @Override
+ public boolean isDone() {
+ return future.isDone();
+ }
+ };
+ }
+ }
+
+ private final ChannelListener.ChannelListenerFactory listenerFactory;
+ private final SSLEngine engine;
+ private final ClassLoader classLoader;
+ private Map<Channel, ChannelListener> listeners = Collections.synchronizedMap(new HashMap<Channel, ChannelListener>());
+ private AtomicLong objectsRead = new AtomicLong(0);
+ private AtomicLong objectsWritten = new AtomicLong(0);
+ private volatile int maxChannels;
+
+ private ChannelFutureListener completionListener = new ChannelFutureListener() {
+
+ @Override
+ public void operationComplete(ChannelFuture arg0)
+ throws Exception {
+ if (arg0.isSuccess()) {
+ objectsWritten.getAndIncrement();
+ }
+ }
+
+ };
+
+ public SSLAwareChannelHandler(ChannelListener.ChannelListenerFactory listenerFactory,
+ SSLEngine engine, ClassLoader classloader) {
+ this.listenerFactory = listenerFactory;
+ this.engine = engine;
+ this.classLoader = classloader;
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ final ChannelStateEvent e) throws Exception {
+ ChannelListener listener = this.listenerFactory.createChannelListener(new ObjectChannelImpl(e.getChannel()));
+ synchronized (this.listeners) {
+ this.listeners.put(e.getChannel(), listener);
+ maxChannels = Math.max(maxChannels, this.listeners.size());
+ }
+ if (engine != null) {
+ SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
+ sslHandler.handshake(e.getChannel()).addListener(new ChannelFutureListener() {
+ public void operationComplete(ChannelFuture arg0)
+ throws Exception {
+ onConnection(e.getChannel());
+ }
+ });
+ } else {
+ onConnection(e.getChannel());
+ }
+ }
+
+ private void onConnection(Channel channel) throws Exception {
+ ChannelListener listener = this.listeners.get(channel);
+ if (listener != null) {
+ listener.onConnection();
+ }
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx,
+ ExceptionEvent e) throws Exception {
+ ChannelListener listener = this.listeners.get(e.getChannel());
+ if (listener != null) {
+ listener.exceptionOccurred(e.getCause());
+ }
+ e.getChannel().close();
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx,
+ MessageEvent e) throws Exception {
+ objectsRead.getAndIncrement();
+ ChannelListener listener = this.listeners.get(e.getChannel());
+ if (listener != null) {
+ listener.receivedMessage(e.getMessage());
+ }
+ }
+
+ @Override
+ public void channelDisconnected(ChannelHandlerContext ctx,
+ ChannelStateEvent e) throws Exception {
+ ChannelListener listener = this.listeners.remove(e.getChannel());
+ if (listener != null) {
+ listener.exceptionOccurred(new SingleInstanceCommunicationException(CommPlatformPlugin.Util.getString("SSLAwareChannelHandler.channel_closed"))); //$NON-NLS-1$
+ }
+ }
+
+ public ChannelPipeline getPipeline() throws Exception {
+ ChannelPipeline pipeline = new DefaultChannelPipeline();
+
+ if (engine != null) {
+ pipeline.addLast("ssl", new SslHandler(engine)); //$NON-NLS-1$
+ }
+ pipeline.addLast("decoder", new ObjectDecoder(1 << 24, classLoader)); //$NON-NLS-1$
+ pipeline.addLast("encoder", new ObjectEncoder()); //$NON-NLS-1$
+ pipeline.addLast("handler", this); //$NON-NLS-1$
+ return pipeline;
+ }
+
+ public long getObjectsRead() {
+ return this.objectsRead.get();
+ }
+
+ public long getObjectsWritten() {
+ return this.objectsWritten.get();
+ }
+
+ public int getConnectedChannels() {
+ return this.listeners.size();
+ }
+
+ public int getMaxConnectedChannels() {
+ return this.maxChannels;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/embedded/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/embedded/src/main/java/org/teiid/transport/SSLConfiguration.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/SSLConfiguration.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/SSLConfiguration.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.util.Arrays;
+import java.util.Properties;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+
+import com.metamatrix.common.comm.platform.socket.SocketUtil;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.common.util.crypto.CryptoException;
+import com.metamatrix.common.util.crypto.CryptoUtil;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.Assertion;
+
+
+public class SSLConfiguration {
+
+ private static final String SSL_ENABLED = "ssl.enabled"; //$NON-NLS-1$
+
+ private static final String KEYSTORE_FILENAME = "ssl.keystore.filename"; //$NON-NLS-1$
+ private static final String KEYSTORE_PASSWORD = "ssl.keystore.Password"; //$NON-NLS-1$
+ private static final String KEYSTORE_TYPE = "ssl.keystoretype"; //$NON-NLS-1$
+ private static final String SSL_PROTOCOL = "ssl.protocol"; //$NON-NLS-1$
+ private static final String KEY_MANAGER_ALGORITHM = "ssl.keymanagementalgorithm"; //$NON-NLS-1$
+
+ private static final String TRUSTSTORE_FILENAME = "ssl.truststore.filename"; //$NON-NLS-1$
+ private static final String TRUSTSTORE_PASSWORD = "ssl.truststore.Password"; //$NON-NLS-1$
+ private static final String AUTHENTICATION_MODE = "ssl.authenticationMode"; //$NON-NLS-1$
+ private static final String CLIENT_ENCRYPTION_ENABLED = "client.encryption.enabled"; //$NON-NLS-1$
+
+ private static final String ONEWAY = "1-way"; //$NON-NLS-1$ - one way is the default
+ private static final String TWOWAY = "2-way"; //$NON-NLS-1$
+ private static final String ANONYMOUS = "anonymous"; //$NON-NLS-1$
+
+ private static final String DEFAULT_SSL_PROTOCOL = "SSLv3"; //$NON-NLS-1$
+ private static final String DEFAULT_KEYSTORE_TYPE = "JKS"; //$NON-NLS-1$
+
+ /*
+ * External SSL resource settings
+ */
+ private boolean ssl_enabled;
+ private String sslProtocol = DEFAULT_SSL_PROTOCOL;
+ private String keyManagerFactoryAlgorithm;
+ private String keyStoreType = DEFAULT_KEYSTORE_TYPE;
+ private String keyStoreFileName;
+ private String keyStorePassword = ""; //$NON-NLS-1$
+ private String trustStoreFileName;
+ private String trustStorePassword = ""; //$NON-NLS-1$
+ private String authenticationMode = ONEWAY;
+
+ /*
+ * Client encryption property. This may belong somewhere else
+ */
+ boolean client_encryption_enabled = false;
+
+ public void init(Properties props) {
+ ssl_enabled = PropertiesUtils.getBooleanProperty(props, SSL_ENABLED, false);
+
+ if (ssl_enabled) {
+ client_encryption_enabled = PropertiesUtils.getBooleanProperty(props, CLIENT_ENCRYPTION_ENABLED, true);
+
+ keyStoreFileName = props.getProperty(KEYSTORE_FILENAME);
+ try {
+ keyStorePassword = CryptoUtil.stringDecrypt(props.getProperty(KEYSTORE_PASSWORD, "")); //$NON-NLS-1$
+ } catch (CryptoException err) {
+ throw new MetaMatrixRuntimeException(err);
+ }
+
+ keyStoreType = props.getProperty(KEYSTORE_TYPE, DEFAULT_KEYSTORE_TYPE);
+
+ keyManagerFactoryAlgorithm = props.getProperty(KEY_MANAGER_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
+
+ authenticationMode = props.getProperty(AUTHENTICATION_MODE);
+
+ trustStoreFileName = props.getProperty(TRUSTSTORE_FILENAME);
+ try {
+ trustStorePassword = CryptoUtil.stringDecrypt(props.getProperty(TRUSTSTORE_PASSWORD, "")); //$NON-NLS-1$
+ } catch (CryptoException err) {
+ throw new MetaMatrixRuntimeException(err);
+ }
+
+ sslProtocol = props.getProperty(SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL);
+ }
+ }
+
+ public SSLEngine getServerSSLEngine() throws IOException, GeneralSecurityException {
+ if (!isServerSSLEnabled()) {
+ return null;
+ }
+
+ // Use the SSLContext to create an SSLServerSocketFactory.
+ SSLContext context = null;
+
+ if (ANONYMOUS.equals(authenticationMode)) {
+ context = SocketUtil.getAnonSSLContext();
+ } else {
+ context = SocketUtil.getSSLContext(keyStoreFileName,
+ keyStorePassword,
+ trustStoreFileName,
+ trustStorePassword,
+ keyManagerFactoryAlgorithm,
+ keyStoreType,
+ sslProtocol);
+ }
+
+ SSLEngine result = context.createSSLEngine();
+ result.setUseClientMode(false);
+ if (ANONYMOUS.equals(authenticationMode)) {
+ Assertion.assertTrue(Arrays.asList(result.getSupportedCipherSuites()).contains(SocketUtil.ANON_CIPHER_SUITE));
+ result.setEnabledCipherSuites(new String[] {
+ SocketUtil.ANON_CIPHER_SUITE
+ });
+ }
+ result.setNeedClientAuth(TWOWAY.equals(authenticationMode));
+ return result;
+ }
+
+ public boolean isServerSSLEnabled() {
+ return ssl_enabled && CryptoUtil.isEncryptionEnabled();
+ }
+
+ public boolean isClientEncryptionEnabled() {
+ return CryptoUtil.isEncryptionEnabled() && client_encryption_enabled;
+ }
+
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/transport/SSLConfiguration.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/embedded/src/main/java/org/teiid/transport/ServerWorkItem.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/ServerWorkItem.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/ServerWorkItem.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/**
+ *
+ */
+package org.teiid.transport;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.ExecutionException;
+
+import javax.crypto.SealedObject;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.admin.api.exception.AdminProcessingException;
+import com.metamatrix.api.exception.ComponentNotFoundException;
+import com.metamatrix.api.exception.ExceptionHolder;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.api.Message;
+import com.metamatrix.common.comm.platform.socket.client.ServiceInvocationStruct;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.util.LogConstants;
+import com.metamatrix.common.util.crypto.CryptoException;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.ReflectionHelper;
+import com.metamatrix.dqp.client.ResultsFuture;
+import com.metamatrix.platform.PlatformPlugin;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+
+public class ServerWorkItem implements Runnable {
+ private final ClientInstance socketClientInstance;
+ private final Serializable messageKey;
+ private final Message message;
+ private final ClientServiceRegistry server;
+ private final SessionServiceInterface sessionService;
+
+ public ServerWorkItem(ClientInstance socketClientInstance,
+ Serializable messageKey, Message message,
+ ClientServiceRegistry server, SessionServiceInterface sessionService) {
+ this.socketClientInstance = socketClientInstance;
+ this.messageKey = messageKey;
+ this.message = message;
+ this.server = server;
+ this.sessionService = sessionService;
+ }
+
+ /**
+ * main entry point for remote method calls. encryption/decryption is
+ * handled here so that it won't be done by the io thread
+ */
+ public void run() {
+ DQPWorkContext.setWorkContext(this.socketClientInstance.getWorkContext());
+ Message result = null;
+ String service = null;
+ final boolean encrypt = message.getContents() instanceof SealedObject;
+ try {
+ message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
+
+ if (!(message.getContents() instanceof ServiceInvocationStruct)) {
+ throw new AssertionError("unknown message contents"); //$NON-NLS-1$
+ }
+ final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)message.getContents();
+ Object instance = server.getClientService(serviceStruct.targetClass);
+ if (instance == null) {
+ throw new ComponentNotFoundException(PlatformPlugin.Util.getString("ServerWorkItem.Component_Not_Found", serviceStruct.targetClass)); //$NON-NLS-1$
+ }
+ if (!(instance instanceof ILogon)) {
+ DQPWorkContext workContext = this.socketClientInstance.getWorkContext();
+ sessionService.validateSession(workContext.getSessionId());
+ }
+ service = serviceStruct.targetClass;
+ ReflectionHelper helper = new ReflectionHelper(instance.getClass());
+ Method m = helper.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
+ Object methodResult;
+ try {
+ methodResult = m.invoke(instance, serviceStruct.args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
+ ResultsFuture<Serializable> future = (ResultsFuture<Serializable>) methodResult;
+ future.addCompletionListener(new ResultsFuture.CompletionListener<Serializable>() {
+
+ public void onCompletion(
+ ResultsFuture<Serializable> completedFuture) {
+ Message asynchResult = new Message();
+ try {
+ asynchResult.setContents(completedFuture.get());
+ } catch (InterruptedException e) {
+ asynchResult.setContents(processException(e, serviceStruct.targetClass));
+ } catch (ExecutionException e) {
+ asynchResult.setContents(processException(e.getCause(), serviceStruct.targetClass));
+ }
+ sendResult(asynchResult, encrypt);
+ }
+
+ });
+ } else { // synch call
+ Message resultHolder = new Message();
+ resultHolder.setContents((Serializable)methodResult);
+ result = resultHolder;
+ }
+ } catch (Throwable t) {
+ Message holder = new Message();
+ holder.setContents(processException(t, service));
+ result = holder;
+ }
+ if (result != null) {
+ sendResult(result, encrypt);
+ }
+ }
+
+ void sendResult(Message result, boolean encrypt) {
+ if (encrypt) {
+ try {
+ result.setContents(socketClientInstance.getCryptor().sealObject(result.getContents()));
+ } catch (CryptoException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+ socketClientInstance.send(result, messageKey);
+ }
+
+ private Serializable processException(Throwable e, String service) {
+ String context = null;
+ if (service != null) {
+ context = this.server.getLoggingContextForService(service);
+ }
+ if (context == null) {
+ context = LogConstants.CTX_SERVER;
+ }
+ // Case 5558: Differentiate between system level errors and
+ // processing errors. Only log system level errors as errors,
+ // log the processing errors as warnings only
+ if (e instanceof MetaMatrixProcessingException) {
+ logProcessingException(e, context);
+ } else if (e instanceof AdminProcessingException) {
+ logProcessingException(e, context);
+ } else {
+ LogManager.logError(context, e, PlatformPlugin.Util.getString("ServerWorkItem.Received_exception_processing_request", this.socketClientInstance.getWorkContext().getConnectionID())); //$NON-NLS-1$
+ }
+
+ return new ExceptionHolder(e);
+ }
+
+ private void logProcessingException(Throwable e, String context) {
+ Throwable cause = e;
+ while (cause.getCause() != null && cause != cause.getCause()) {
+ cause = cause.getCause();
+ }
+ StackTraceElement elem = cause.getStackTrace()[0];
+ LogManager.logDetail(context, e, "Processing exception for session", this.socketClientInstance.getWorkContext().getConnectionID()); //$NON-NLS-1$
+ LogManager.logWarning(context, PlatformPlugin.Util.getString("ServerWorkItem.processing_error", e.getMessage(), this.socketClientInstance.getWorkContext().getConnectionID(), e.getClass().getName(), elem)); //$NON-NLS-1$
+ }
+
+}
\ No newline at end of file
Copied: trunk/embedded/src/main/java/org/teiid/transport/SocketClientInstance.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketClientInstance.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/SocketClientInstance.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/SocketClientInstance.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.io.Serializable;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.api.Message;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.platform.CommPlatformPlugin;
+import com.metamatrix.common.comm.platform.socket.Handshake;
+import com.metamatrix.common.comm.platform.socket.ObjectChannel;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.queue.WorkerPool;
+import com.metamatrix.common.util.LogConstants;
+import com.metamatrix.common.util.crypto.CryptoException;
+import com.metamatrix.common.util.crypto.Cryptor;
+import com.metamatrix.common.util.crypto.DhKeyGenerator;
+import com.metamatrix.common.util.crypto.NullCryptor;
+import com.metamatrix.core.log.MessageLevel;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+
+/**
+ * Sockets implementation of the communication framework class representing the server's view of a client connection.
+ * Implements the server-side of the sockets messaging protocol.
+ * The client side of the protocol is implemented in SocketServerInstance.
+ * Users of this class are expected to provide a WorkerPool for processing incoming messages. Users must also call read().
+ * Users also provide a ServerListener implementation. The ServerListener is the application level object
+ * processing the application level messages.
+ */
+public class SocketClientInstance implements ChannelListener, ClientInstance {
+
+ private final ObjectChannel objectSocket;
+ private final WorkerPool workerPool;
+ private final ClientServiceRegistry server;
+ private Cryptor cryptor;
+ private boolean usingEncryption;
+ private DhKeyGenerator keyGen;
+ private DQPWorkContext workContext = new DQPWorkContext();
+ private SessionServiceInterface sessionService;
+
+ public SocketClientInstance(ObjectChannel objectSocket, WorkerPool workerPool, ClientServiceRegistry server, boolean isClientEncryptionEnabled, SessionServiceInterface sessionService) {
+ this.objectSocket = objectSocket;
+ this.workerPool = workerPool;
+ this.server = server;
+ this.usingEncryption = isClientEncryptionEnabled;
+ this.sessionService = sessionService;
+ SocketAddress address = this.objectSocket.getRemoteAddress();
+ if (address instanceof InetSocketAddress) {
+ InetSocketAddress addr = (InetSocketAddress)address;
+ this.workContext.setClientAddress(addr.getAddress().getHostAddress());
+ this.workContext.setClientHostname(addr.getHostName());
+ }
+ }
+
+ public void send(Message message, Serializable messageKey) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SERVER, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_SERVER, " message: " + message + " for request ID:" + messageKey); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ message.setMessageKey(messageKey);
+ objectSocket.write(message);
+ }
+
+ /**
+ * @return Returns the cryptor.
+ */
+ public Cryptor getCryptor() {
+ return this.cryptor;
+ }
+
+ public void exceptionOccurred(Throwable t) {
+ LogManager.logDetail(LogConstants.CTX_SERVER, t, "Unhandled exception, closing client instance"); //$NON-NLS-1$
+ }
+
+ public void onConnection() throws CommunicationException {
+ Handshake handshake = new Handshake();
+ handshake.setVersion(SocketListener.getVersionInfo());
+
+ if (usingEncryption) {
+ keyGen = new DhKeyGenerator();
+ byte[] publicKey;
+ try {
+ publicKey = keyGen.createPublicKey();
+ } catch (CryptoException e) {
+ throw new CommunicationException(e);
+ }
+ handshake.setPublicKey(publicKey);
+ }
+ this.objectSocket.write(handshake);
+ }
+
+ private void receivedHahdshake(Handshake handshake) throws CommunicationException {
+ if (usingEncryption) {
+ byte[] returnedPublicKey = handshake.getPublicKey();
+
+ //ensure the key information
+ if (returnedPublicKey == null) {
+ throw new CommunicationException(CommPlatformPlugin.Util.getString("SocketClientInstance.invalid_sessionkey")); //$NON-NLS-1$
+ }
+
+ try {
+ this.cryptor = keyGen.getSymmetricCryptor(returnedPublicKey);
+ } catch (CryptoException e) {
+ throw new CommunicationException(e);
+ }
+ this.keyGen = null;
+ } else {
+ this.cryptor = new NullCryptor();
+ }
+ }
+
+ public void receivedMessage(Object msg) throws CommunicationException {
+ if (msg instanceof Message) {
+ processMessagePacket((Message)msg);
+ } else if (msg instanceof Handshake) {
+ receivedHahdshake((Handshake)msg);
+ }
+ }
+
+ private void processMessagePacket(Message packet) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SERVER, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_SERVER, "processing message:" + packet); //$NON-NLS-1$
+ }
+ workerPool.execute(new ServerWorkItem(this, packet.getMessageKey(), packet, this.server, this.sessionService));
+ }
+
+ public void shutdown() throws CommunicationException {
+ this.objectSocket.close();
+ }
+
+ public DQPWorkContext getWorkContext() {
+ return this.workContext;
+ }
+}
Copied: trunk/embedded/src/main/java/org/teiid/transport/SocketListener.java (from rev 1067, trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketListener.java)
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/SocketListener.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/SocketListener.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.net.ssl.SSLEngine;
+
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.teiid.transport.ChannelListener.ChannelListenerFactory;
+
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.platform.socket.ObjectChannel;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.queue.WorkerPool;
+import com.metamatrix.common.queue.WorkerPoolFactory;
+import com.metamatrix.common.queue.WorkerPoolStats;
+import com.metamatrix.common.util.ApplicationInfo;
+import com.metamatrix.common.util.LogConstants;
+import com.metamatrix.core.log.MessageLevel;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+import com.metamatrix.platform.vm.controller.SocketListenerStats;
+
+/**
+ * Server-side class to listen for new connection requests and create a SocketClientConnection for each connection request.
+ */
+public class SocketListener implements ChannelListenerFactory {
+ private ClientServiceRegistry server;
+ private SSLAwareChannelHandler channelHandler;
+ private Channel serverChanel;
+ private boolean isClientEncryptionEnabled;
+ private SessionServiceInterface sessionService;
+ private WorkerPool workerPool;
+ private ExecutorService nettyPool;
+
+ /**
+ *
+ * @param port
+ * @param bindaddress
+ * @param server
+ * @param inputBufferSize
+ * @param outputBufferSize
+ * @param workerPool
+ * @param engine null if SSL is disabled
+ */
+ public SocketListener(int port, String bindAddress, ClientServiceRegistry server, int inputBufferSize,
+ int outputBufferSize, int maxWorkers, SSLEngine engine, boolean isClientEncryptionEnabled, SessionServiceInterface sessionService) {
+ this.isClientEncryptionEnabled = isClientEncryptionEnabled;
+ this.sessionService = sessionService;
+ if (port < 0 || port > 0xFFFF) {
+ throw new IllegalArgumentException("port out of range:" + port); //$NON-NLS-1$
+ }
+
+ this.server = server;
+ this.workerPool = WorkerPoolFactory.newWorkerPool("SocketWorker", maxWorkers); //$NON-NLS-1$
+ this.nettyPool = Executors.newCachedThreadPool();
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SERVER, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_SERVER, "server = " + this.server + "binding to port:" + port); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ ChannelFactory factory = new NioServerSocketChannelFactory(nettyPool, nettyPool, Math.min(Runtime.getRuntime().availableProcessors(), maxWorkers));
+
+ ServerBootstrap bootstrap = new ServerBootstrap(factory);
+ this.channelHandler = new SSLAwareChannelHandler(this, engine, Thread.currentThread().getContextClassLoader());
+ bootstrap.setPipelineFactory(channelHandler);
+ if (inputBufferSize != 0) {
+ bootstrap.setOption("receiveBufferSize", new Integer(inputBufferSize)); //$NON-NLS-1$
+ }
+ if (outputBufferSize != 0) {
+ bootstrap.setOption("sendBufferSize", new Integer(outputBufferSize)); //$NON-NLS-1$
+ }
+ bootstrap.setOption("keepAlive", Boolean.TRUE); //$NON-NLS-1$
+
+ this.serverChanel = bootstrap.bind(new InetSocketAddress(bindAddress, port));
+ }
+
+ public WorkerPoolStats getProcessPoolStats() {
+ return this.workerPool.getStats();
+ }
+
+ public int getPort() {
+ return ((InetSocketAddress)this.serverChanel.getLocalAddress()).getPort();
+ }
+
+ static String getVersionInfo() {
+ return ApplicationInfo.getInstance().getMajorReleaseNumber();
+ }
+
+ public void stop() {
+ this.serverChanel.close();
+ this.workerPool.shutdownNow();
+ this.nettyPool.shutdownNow();
+ }
+
+ public SocketListenerStats getStats() {
+ SocketListenerStats stats = new SocketListenerStats();
+ stats.objectsRead = this.channelHandler.getObjectsRead();
+ stats.objectsWritten = this.channelHandler.getObjectsWritten();
+ stats.sockets = this.channelHandler.getConnectedChannels();
+ stats.maxSockets = this.channelHandler.getMaxConnectedChannels();
+ return stats;
+ }
+
+ public ChannelListener createChannelListener(ObjectChannel channel) {
+ return new SocketClientInstance(channel, this.workerPool, this.server, this.isClientEncryptionEnabled, this.sessionService);
+ }
+
+}
\ No newline at end of file
Added: trunk/embedded/src/main/java/org/teiid/transport/SocketTransport.java
===================================================================
--- trunk/embedded/src/main/java/org/teiid/transport/SocketTransport.java (rev 0)
+++ trunk/embedded/src/main/java/org/teiid/transport/SocketTransport.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.transport;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+import java.util.Properties;
+
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.util.LogConstants;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
+import com.metamatrix.platform.PlatformPlugin;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+
+/**
+ * This class starts a Socket for DQP connections and listens on the port and hands out the connections to the
+ * users
+ */
+public class SocketTransport {
+
+ private static final int DEFAULT_SERVER_PORT = 31000;
+ private static final int DEFAULT_MAX_THREADS = 15;
+ private static final int DEFAULT_INPUT_BUFFER_SIZE = 0;
+ private static final int DEFAULT_OUTPUT_BUFFER_SIZE = 0;
+
+ private Properties props;
+ private SocketListener listener;
+
+ private SessionServiceInterface sessionSerice;
+ protected ClientServiceRegistry clientServices;
+
+ public SocketTransport(Properties props, ClientServiceRegistry serivices, SessionServiceInterface sessionService) {
+ this.props = props;
+ this.clientServices = serivices;
+ this.sessionSerice = sessionService;
+ }
+
+ public void start() {
+ int socketPort = PropertiesUtils.getIntProperty(this.props, DQPEmbeddedProperties.SERVER_PORT, DEFAULT_SERVER_PORT);
+ int maxThreads = PropertiesUtils.getIntProperty(this.props, DQPEmbeddedProperties.MAX_THREADS, DEFAULT_MAX_THREADS);
+ int inputBufferSize = PropertiesUtils.getIntProperty(this.props, DQPEmbeddedProperties.INPUT_BUFFER_SIZE, DEFAULT_INPUT_BUFFER_SIZE);
+ int outputBufferSize = PropertiesUtils.getIntProperty(this.props, DQPEmbeddedProperties.OUTPUT_BUFFER_SIZE, DEFAULT_OUTPUT_BUFFER_SIZE);
+ String bindAddress = ((InetAddress)props.get(DQPEmbeddedProperties.HOST_ADDRESS)).getHostAddress();
+
+ try {
+ SSLConfiguration helper = new SSLConfiguration();
+ helper.init(this.props);
+
+ LogManager.logDetail(LogConstants.CTX_SERVER, PlatformPlugin.Util.getString("SocketVMController.1", new Object[] {bindAddress, String.valueOf(socketPort)})); //$NON-NLS-1$
+ this.listener = new SocketListener(socketPort, bindAddress, this.clientServices, inputBufferSize, outputBufferSize, maxThreads, helper.getServerSSLEngine(), helper.isClientEncryptionEnabled(), this.sessionSerice);
+
+ } catch (UnknownHostException e) {
+ throw new MetaMatrixRuntimeException(e, PlatformPlugin.Util.getString("SocketVMController.2",new Object[] {bindAddress, String.valueOf(socketPort)})); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new MetaMatrixRuntimeException(e, PlatformPlugin.Util.getString("SocketVMController.2",new Object[] {bindAddress, String.valueOf(socketPort)})); //$NON-NLS-1$
+ } catch (GeneralSecurityException e) {
+ throw new MetaMatrixRuntimeException(e, PlatformPlugin.Util.getString("SocketVMController.2",new Object[] {bindAddress, String.valueOf(socketPort)})); //$NON-NLS-1$
+ }
+ }
+
+ public void stop() {
+ this.listener.stop();
+ }
+}
Property changes on: trunk/embedded/src/main/java/org/teiid/transport/SocketTransport.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/embedded/src/main/resources/com/metamatrix/platform/i18n.properties
===================================================================
--- trunk/embedded/src/main/resources/com/metamatrix/platform/i18n.properties 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/main/resources/com/metamatrix/platform/i18n.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1280,7 +1280,7 @@
ServerWorkItem.Component_Not_Found=Component not found: {0}
SocketVMController.0=Register Admin API
-SocketVMController.1={0} is bound to address {1} listening on port {2}
+SocketVMController.1=Bound to address {1} listening on port {2}
SocketVMController.2=Problem starting server binding to address {0} and listening on port {1}
SocketVMController.3=Setting Server Listener listenerFilter={0}
SocketVMController.4=Getting ServerListener Registry: {0}
@@ -1289,4 +1289,5 @@
RemoteProxy.localCallFailed=Remote client could not invoke local service method {0} on {1}
JGroupsMessageBus.noResponse=No response for remote method call
commonextensionspath_in_use=Extension modules "{0}" are in scope to create the service - {1}
-commonextensionspath_not_in_use=Failed to use extension modules "{0}" to create the service -{1}
\ No newline at end of file
+commonextensionspath_not_in_use=Failed to use extension modules "{0}" to create the service -{1}
+LogonImpl.Invalid_use_of_credentials_and_token=Conflicting use of both client session token and credentials.
\ No newline at end of file
Modified: trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/TestEmbeddedConfigSource.java
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/TestEmbeddedConfigSource.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/TestEmbeddedConfigSource.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -28,12 +28,15 @@
import junit.framework.TestCase;
-import com.metamatrix.common.application.Application;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
import com.metamatrix.common.protocol.URLHelper;
import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.dqp.service.DQPServiceNames;
+import com.metamatrix.dqp.service.ConfigurationService;
import com.metamatrix.dqp.service.FakeAbstractService;
import com.metamatrix.dqp.service.FakeVDBService;
+import com.metamatrix.dqp.service.VDBService;
+import com.metamatrix.jdbc.EmbeddedGuiceModule;
public class TestEmbeddedConfigSource extends TestCase {
@@ -49,11 +52,14 @@
Properties p = new Properties();
URL url = buildDQPUrl(UnitTestUtil.getTestDataPath() + "/bqt/fakebqt.properties"); //$NON-NLS-1$
p.load(url.openStream());
- EmbeddedConfigSource source = new EmbeddedConfigSource(url, p);
- Application application = new Application();
- application.start(source);
- assertTrue(application.getEnvironment().findService(DQPServiceNames.VDB_SERVICE) instanceof FakeVDBService);
- assertTrue(application.getEnvironment().findService(DQPServiceNames.CONFIGURATION_SERVICE) instanceof FakeAbstractService);
+
+ EmbeddedGuiceModule source = new EmbeddedGuiceModule(url, p);
+ Injector injector = Guice.createInjector(source);
+ source.setInjector(injector);
+
+
+ assertTrue(source.getServiceInstance(VDBService.class) instanceof FakeVDBService);
+ assertTrue(source.getServiceInstance(ConfigurationService.class) instanceof FakeAbstractService);
}
}
Copied: trunk/embedded/src/test/java/com/metamatrix/platform/security/TestAdminAuthInterceptor.java (from rev 1067, trunk/server/src/test/java/com/metamatrix/common/comm/platform/server/TestAdminAuthInterceptor.java)
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/platform/security/TestAdminAuthInterceptor.java (rev 0)
+++ trunk/embedded/src/test/java/com/metamatrix/platform/security/TestAdminAuthInterceptor.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.platform.security;
+
+import java.lang.reflect.Proxy;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.transport.AdminAuthorizationInterceptor;
+
+import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.admin.api.exception.AdminProcessingException;
+import com.metamatrix.admin.api.server.AdminRoles;
+import com.metamatrix.admin.api.server.ServerAdmin;
+import com.metamatrix.api.exception.security.AuthorizationException;
+import com.metamatrix.api.exception.security.AuthorizationMgmtException;
+import com.metamatrix.core.util.SimpleMock;
+import com.metamatrix.dqp.service.AuthorizationService;
+import com.metamatrix.platform.admin.api.ExtensionSourceAdminAPI;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
+import com.metamatrix.platform.security.api.SessionToken;
+
+
+/**
+ * @since 4.3
+ */
+public class TestAdminAuthInterceptor {
+
+ @Before public void setUp() throws Exception {
+ DQPWorkContext.getWorkContext().setSessionToken(new SessionToken(new MetaMatrixSessionID(1), "gojo")); //$NON-NLS-1$
+ }
+
+ @After public void tearDown() throws Exception {
+ DQPWorkContext.setWorkContext(new DQPWorkContext());
+ }
+
+ @Test(expected=AdminProcessingException.class) public void testAddUserUDF_fail() throws AdminException {
+ Set<String> userRoles = new HashSet<String>();
+ ServerAdmin serverAdmin = getTestServerAdmin(userRoles, ServerAdmin.class);
+ serverAdmin.addUDF(null, null);
+ }
+
+ private <T> T getTestServerAdmin(final Set<String> userRoles, Class<T> iface) {
+ return getTestServerAdmin(userRoles, iface, SimpleMock.createSimpleMock(iface));
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> T getTestServerAdmin(final Set<String> userRoles, Class<T> iface, T impl) {
+ AuthorizationService service = Mockito.mock(AuthorizationService.class);
+ try {
+ Mockito.stub(service.isCallerInRole((SessionToken)Mockito.anyObject(), Mockito.argThat(new BaseMatcher<String>() {
+ @Override
+ public boolean matches(Object arg0) {
+ return userRoles.contains(arg0);
+ }
+
+ @Override
+ public void describeTo(Description arg0) {
+
+ }
+ }))).toReturn(Boolean.TRUE);
+ } catch (AuthorizationMgmtException e) {
+ throw new RuntimeException(e);
+ }
+ AdminAuthorizationInterceptor authInterceptor = new AdminAuthorizationInterceptor(service, impl);
+ return (T)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {iface}, authInterceptor);
+ }
+
+ @Test public void testAddUDF_succeed() throws Exception {
+ Set<String> userRoles = new HashSet<String>();
+ userRoles.add(AdminRoles.RoleName.ADMIN_SYSTEM);
+ ServerAdmin serverAdmin = getTestServerAdmin(userRoles, ServerAdmin.class);
+ serverAdmin.addUDF(null, null);
+ }
+
+ @Test public void testGetVDBs() throws Exception {
+ Set<String> userRoles = new HashSet<String>();
+ ServerAdmin serverAdmin = getTestServerAdmin(userRoles, ServerAdmin.class);
+ serverAdmin.getVDBs("*"); //$NON-NLS-1$
+ }
+
+ @Test(expected=AdminProcessingException.class) public void testReadOnlyFails() throws Exception {
+ Set<String> userRoles = new HashSet<String>();
+ ServerAdmin serverAdmin = getTestServerAdmin(userRoles, ServerAdmin.class);
+ serverAdmin.getSessions("*"); //$NON-NLS-1$
+ }
+
+ @Test public void testBounce_succeed() throws Exception {
+ Set<String> userRoles = new HashSet<String>();
+ userRoles.add(AdminRoles.RoleName.ADMIN_PRODUCT);
+ ServerAdmin serverAdmin = getTestServerAdmin(userRoles, ServerAdmin.class);
+ serverAdmin.bounceSystem(false);
+ }
+
+
+}
Modified: trunk/embedded/src/test/java/com/metamatrix/platform/security/membership/service/TestMembershipServiceImpl.java
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/platform/security/membership/service/TestMembershipServiceImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/embedded/src/test/java/com/metamatrix/platform/security/membership/service/TestMembershipServiceImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,6 +22,8 @@
package com.metamatrix.platform.security.membership.service;
+import java.net.Inet4Address;
+import java.net.InetAddress;
import java.util.Properties;
import java.util.regex.Pattern;
@@ -47,7 +49,7 @@
p.setProperty(MembershipServiceInterface.ADMIN_USERNAME, "metamatrixadmin"); //$NON-NLS-1$
p.setProperty(MembershipServiceInterface.ADMIN_PASSWORD, CryptoUtil.getCryptor().encrypt("mm")); //$NON-NLS-1$
p.setProperty(MembershipServiceInterface.SECURITY_ENABLED, Boolean.TRUE.toString());
- MembershipServiceImpl membershipServiceImpl = new MembershipServiceImpl();
+ MembershipServiceImpl membershipServiceImpl = new MembershipServiceImpl(null, null);
membershipServiceImpl.initialize(p);
@@ -60,7 +62,7 @@
p.setProperty(MembershipServiceInterface.ADMIN_USERNAME, "metamatrixadmin"); //$NON-NLS-1$
p.setProperty(MembershipServiceInterface.ADMIN_PASSWORD, CryptoUtil.getCryptor().encrypt("mm")); //$NON-NLS-1$
p.setProperty(MembershipServiceInterface.SECURITY_ENABLED, Boolean.FALSE.toString());
- MembershipServiceImpl membershipServiceImpl = new MembershipServiceImpl();
+ MembershipServiceImpl membershipServiceImpl = new MembershipServiceImpl(null,null);
membershipServiceImpl.initialize(p);
@@ -81,8 +83,8 @@
assertEquals("@", MembershipServiceImpl.getBaseUsername("@")); //$NON-NLS-1$ //$NON-NLS-2$
}
- private MembershipServiceImpl createMembershipService() throws MembershipSourceException {
- MembershipServiceImpl membershipService = new MembershipServiceImpl();
+ private MembershipServiceImpl createMembershipService() throws Exception {
+ MembershipServiceImpl membershipService = new MembershipServiceImpl(null, InetAddress.getLocalHost());
MembershipServiceImpl.MembershipDomainHolder membershipDomainHolder = new MembershipServiceImpl.MembershipDomainHolder(
TestFileMembershipDomain
.createFileMembershipDomain(),
Copied: trunk/embedded/src/test/java/org/teiid/transport/TestCommSockets.java (from rev 1067, trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java)
===================================================================
--- trunk/embedded/src/test/java/org/teiid/transport/TestCommSockets.java (rev 0)
+++ trunk/embedded/src/test/java/org/teiid/transport/TestCommSockets.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2008 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor
+ * license agreements. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.transport;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+import java.net.InetSocketAddress;
+import java.util.Properties;
+
+import javax.net.ssl.SSLEngine;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.transport.LogonImpl;
+import org.teiid.transport.SocketListener;
+
+import com.metamatrix.api.exception.ComponentNotFoundException;
+import com.metamatrix.api.exception.security.LogonException;
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.exception.ConnectionException;
+import com.metamatrix.common.comm.platform.socket.SocketUtil;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerConnection;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerConnectionFactory;
+import com.metamatrix.common.comm.platform.socket.client.UrlServerDiscovery;
+import com.metamatrix.common.util.crypto.NullCryptor;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.LogonResult;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+import com.metamatrix.platform.vm.controller.SocketListenerStats;
+
+public class TestCommSockets {
+
+ SocketListener listener;
+ private SocketServerConnectionFactory sscf;
+ private InetSocketAddress addr;
+
+ @Before public void setUp() {
+ addr = new InetSocketAddress(0);
+ }
+
+ @After public void tearDown() throws Exception {
+ if (listener != null) {
+ listener.stop();
+ }
+ }
+
+ @Test public void testFailedConnect() throws Exception {
+ ClientServiceRegistry csr = new ClientServiceRegistry();
+ SessionServiceInterface sessionService = mock(SessionServiceInterface.class);
+ csr.registerClientService(ILogon.class, new LogonImpl(sessionService, "fakeCluster"), "foo"); //$NON-NLS-1$ //$NON-NLS-2$
+ listener = new SocketListener(addr.getPort(), addr.getAddress().getHostAddress(),
+ csr, 1024, 1024, 1, null, true, sessionService);
+
+ try {
+ Properties p = new Properties();
+ String url = new MMURL(addr.getHostName(), listener.getPort() - 1, false).getAppServerURL();
+ p.setProperty(MMURL.CONNECTION.SERVER_URL, url); //wrong port
+ SocketServerConnectionFactory.getInstance().createConnection(p);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (CommunicationException e) {
+
+ }
+ }
+
+ @Test public void testConnectWithoutPooling() throws Exception {
+ Properties p = new Properties();
+ p.setProperty("org.teiid.sockets.maxCachedInstances", String.valueOf(0)); //$NON-NLS-1$
+ SocketServerConnection conn = helpEstablishConnection(false, null, true, p);
+ SocketListenerStats stats = listener.getStats();
+ assertEquals(2, stats.objectsRead); // handshake response, logon,
+ assertEquals(1, stats.sockets);
+ conn.shutdown();
+ stats = listener.getStats();
+ assertEquals(1, stats.maxSockets);
+ assertEquals(3, stats.objectsRead); // handshake response, logon, logoff
+ if (stats.sockets > 0) {
+ // there is a timing issue here, since the effect of shutdown on the
+ // server side can be delayed
+ Thread.sleep(500);
+ }
+ stats = listener.getStats();
+ assertEquals(0, stats.sockets);
+ }
+
+ @Test public void testConnectWithPooling() throws Exception {
+ SocketServerConnection conn = helpEstablishConnection(false, null);
+ SocketListenerStats stats = listener.getStats();
+ assertEquals(2, stats.objectsRead); // handshake response, logon,
+ assertEquals(1, stats.sockets);
+ conn.shutdown();
+ stats = listener.getStats();
+ assertEquals(1, stats.maxSockets);
+ assertEquals(3, stats.objectsRead); // handshake response, logon, logoff
+ stats = listener.getStats();
+ assertEquals(1, stats.sockets);
+ conn = helpEstablishConnection(false, null);
+ conn.shutdown();
+ stats = listener.getStats();
+ assertEquals(1, stats.sockets);
+ assertEquals(1, stats.maxSockets);
+ }
+
+
+ @Test public void testConnectWithoutClientEncryption() throws Exception {
+ SocketServerConnection conn = helpEstablishConnection(false, null, false, new Properties());
+ assertTrue(conn.selectServerInstance().getCryptor() instanceof NullCryptor);
+ conn.shutdown();
+ }
+
+ private SocketServerConnection helpEstablishConnection(boolean secure,
+ SSLEngine serverSSL) throws CommunicationException, ConnectionException {
+ return helpEstablishConnection(secure, serverSSL, true, new Properties());
+ }
+
+ private SocketServerConnection helpEstablishConnection(boolean secure,
+ SSLEngine serverSSL, boolean isClientEncryptionEnabled, Properties socketConfig) throws CommunicationException,
+ ConnectionException {
+ if (listener == null) {
+ SessionServiceInterface sessionService = mock(SessionServiceInterface.class);
+ ClientServiceRegistry csr = new ClientServiceRegistry();
+ csr.registerClientService(ILogon.class, new LogonImpl(sessionService, "fakeCluster") { //$NON-NLS-1$
+ @Override
+ public LogonResult logon(Properties connProps)
+ throws LogonException, ComponentNotFoundException {
+ return new LogonResult();
+ }
+ }, "foo"); //$NON-NLS-1$
+ listener = new SocketListener(addr.getPort(), addr.getAddress().getHostAddress(),
+ csr, 1024, 1024, 1, serverSSL, isClientEncryptionEnabled, sessionService);
+ SocketListenerStats stats = listener.getStats();
+ assertEquals(0, stats.maxSockets);
+ assertEquals(0, stats.objectsRead);
+ assertEquals(0, stats.objectsWritten);
+ assertEquals(0, stats.sockets);
+ }
+
+ Properties p = new Properties();
+ String url = new MMURL(addr.getHostName(), listener.getPort(),secure).getAppServerURL();
+ p.setProperty(MMURL.CONNECTION.SERVER_URL, url);
+ p.setProperty(MMURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
+ if (sscf == null) {
+ sscf = new SocketServerConnectionFactory();
+ sscf.init(socketConfig);
+ }
+ return sscf.createConnection(p);
+ }
+
+ @Test public void testSSLConnectWithNonSSLServer() throws Exception {
+ try {
+ helpEstablishConnection(true, null);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (CommunicationException e) {
+
+ }
+ }
+
+ @Test public void testAnonSSLConnect() throws Exception {
+ SSLEngine engine = SocketUtil.getAnonSSLContext().createSSLEngine();
+ engine.setUseClientMode(false);
+ engine.setEnabledCipherSuites(new String[] { SocketUtil.ANON_CIPHER_SUITE });
+ Properties p = new Properties();
+ p.setProperty(SocketUtil.TRUSTSTORE_FILENAME, SocketUtil.NONE);
+ SocketServerConnection conn = helpEstablishConnection(true, engine, true, p);
+ conn.shutdown();
+ }
+
+}
Copied: trunk/embedded/src/test/java/org/teiid/transport/TestLogonImpl.java (from rev 1067, trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestLogonImpl.java)
===================================================================
--- trunk/embedded/src/test/java/org/teiid/transport/TestLogonImpl.java (rev 0)
+++ trunk/embedded/src/test/java/org/teiid/transport/TestLogonImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2008 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor
+ * license agreements. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.mockito.Mockito;
+
+import com.metamatrix.api.exception.security.LogonException;
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.platform.security.api.LogonResult;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
+import com.metamatrix.platform.security.api.MetaMatrixSessionInfo;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+
+public class TestLogonImpl extends TestCase {
+
+ public void testLogonResult() throws Exception {
+ SessionServiceInterface ssi = Mockito
+ .mock(SessionServiceInterface.class);
+
+ String userName = "Fred"; //$NON-NLS-1$
+ String applicationName = "test"; //$NON-NLS-1$
+ Properties p = new Properties();
+ p.setProperty(MMURL.CONNECTION.USER_NAME, userName);
+ p.setProperty(MMURL.CONNECTION.APP_NAME, applicationName);
+
+ MetaMatrixSessionInfo resultInfo = new MetaMatrixSessionInfo(
+ new MetaMatrixSessionID(1), userName, 0, applicationName, new Properties(),
+ null, null);
+
+ Mockito.stub(ssi.createSession(userName, null, null, applicationName,
+ p)).toReturn(resultInfo);
+
+ LogonImpl impl = new LogonImpl(ssi, "fakeCluster"); //$NON-NLS-1$
+
+ LogonResult result = impl.logon(p);
+ assertEquals(userName, result.getUserName());
+ assertEquals(new MetaMatrixSessionID(1), result.getSessionID());
+ }
+
+ public void testCredentials() throws Exception {
+ SessionServiceInterface ssi = Mockito.mock(SessionServiceInterface.class);
+ LogonImpl impl = new LogonImpl(ssi, "fakeCluster"); //$NON-NLS-1$
+ Properties p = new Properties();
+ p.put(MMURL.CONNECTION.CLIENT_TOKEN_PROP, new Object());
+ //invalid credentials
+ p.setProperty(MMURL.JDBC.CREDENTIALS, "(...)"); //$NON-NLS-1$
+
+ try {
+ impl.logon(p);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (LogonException e) {
+ assertEquals("Conflicting use of both client session token and credentials.", e.getMessage()); //$NON-NLS-1$
+ }
+
+ p.remove(MMURL.CONNECTION.CLIENT_TOKEN_PROP);
+
+ try {
+ impl.logon(p);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (LogonException e) {
+ assertEquals("Credentials string must contain \"system\" property.", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+}
Copied: trunk/embedded/src/test/java/org/teiid/transport/TestSocketRemoting.java (from rev 1067, trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestSocketRemoting.java)
===================================================================
--- trunk/embedded/src/test/java/org/teiid/transport/TestSocketRemoting.java (rev 0)
+++ trunk/embedded/src/test/java/org/teiid/transport/TestSocketRemoting.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,224 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.transport;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.transport.ClientInstance;
+import org.teiid.transport.ServerWorkItem;
+
+import com.metamatrix.admin.api.exception.security.InvalidSessionException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.security.LogonException;
+import com.metamatrix.common.api.HostInfo;
+import com.metamatrix.common.api.MMURL;
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.api.Message;
+import com.metamatrix.common.comm.api.ResultsReceiver;
+import com.metamatrix.common.comm.exception.CommunicationException;
+import com.metamatrix.common.comm.exception.ConnectionException;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerConnection;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerInstance;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerInstanceFactory;
+import com.metamatrix.common.comm.platform.socket.client.SocketServerInstanceImpl;
+import com.metamatrix.common.comm.platform.socket.client.UrlServerDiscovery;
+import com.metamatrix.common.util.crypto.Cryptor;
+import com.metamatrix.common.util.crypto.NullCryptor;
+import com.metamatrix.common.xa.XATransactionException;
+import com.metamatrix.core.util.SimpleMock;
+import com.metamatrix.dqp.client.ClientSideDQP;
+import com.metamatrix.dqp.client.ResultsFuture;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.LogonResult;
+import com.metamatrix.platform.security.api.SessionToken;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+
+public class TestSocketRemoting extends TestCase {
+
+ public interface FakeService {
+
+ ResultsFuture<Integer> asynchResult();
+
+ String exceptionMethod() throws MetaMatrixProcessingException;
+
+ }
+
+ private static class FakeServiceImpl implements FakeService {
+
+ public ResultsFuture<Integer> asynchResult() {
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ result.getResultsReceiver().receiveResults(new Integer(5));
+ return result;
+ }
+
+ public String exceptionMethod() throws MetaMatrixProcessingException {
+ throw new MetaMatrixProcessingException();
+ }
+
+ }
+
+ private static class FakeClientServerInstance extends SocketServerInstanceImpl implements ClientInstance {
+
+ ClientServiceRegistry clientServiceRegistry;
+ private ResultsReceiver<Object> listener;
+
+ public FakeClientServerInstance(ClientServiceRegistry clientServiceRegistry) {
+ super();
+ this.clientServiceRegistry = clientServiceRegistry;
+ }
+
+ public HostInfo getHostInfo() {
+ return new HostInfo("fake", 1); //$NON-NLS-1$
+ }
+
+ public boolean isOpen() {
+ return true;
+ }
+
+ @Override
+ public void send(Message message, ResultsReceiver<Object> listener,
+ Serializable messageKey) throws CommunicationException,
+ InterruptedException {
+ ServerWorkItem workItem = new ServerWorkItem(this, messageKey, message, clientServiceRegistry, SimpleMock.createSimpleMock(SessionServiceInterface.class));
+ this.listener = listener;
+ workItem.run();
+ }
+
+ public void shutdown() {
+
+ }
+
+ public Cryptor getCryptor() {
+ return new NullCryptor();
+ }
+
+ public DQPWorkContext getWorkContext() {
+ return new DQPWorkContext();
+ }
+
+ public void send(Message message, Serializable messageKey) {
+ this.listener.receiveResults(message.getContents());
+ }
+
+ }
+
+ /**
+ * No server was supplied, will throw an NPE under the covers
+ */
+ public void testUnckedException() throws Exception {
+ FakeClientServerInstance serverInstance = new FakeClientServerInstance(null);
+ try {
+ createFakeConnection(serverInstance);
+ fail("expected exception"); //$NON-NLS-1$
+ } catch (CommunicationException e) {
+ assertEquals("Unable to find a component used in logging on to MetaMatrix", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ public void testMethodInvocation() throws Exception {
+ ClientServiceRegistry csr = new ClientServiceRegistry();
+ csr.registerClientService(ILogon.class, new ILogon() {
+
+ public ResultsFuture<?> logoff()
+ throws InvalidSessionException,
+ MetaMatrixComponentException {
+ ResultsFuture<?> result = new ResultsFuture<Void>();
+ result.getResultsReceiver().exceptionOccurred(new MetaMatrixComponentException("some exception")); //$NON-NLS-1$
+ return result;
+ }
+
+ public LogonResult logon(Properties connectionProperties)
+ throws LogonException, MetaMatrixComponentException {
+ return new LogonResult();
+ }
+
+ // tests asynch where we don't care about the result
+ public ResultsFuture<?> ping() throws InvalidSessionException,
+ MetaMatrixComponentException {
+ return null;
+ }
+
+ @Override
+ public void assertIdentity(SessionToken sessionId)
+ throws InvalidSessionException,
+ MetaMatrixComponentException {
+ }
+
+ }, "foo"); //$NON-NLS-1$
+ csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo"); //$NON-NLS-1$
+ final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
+ SocketServerConnection connection = createFakeConnection(serverInstance);
+ ILogon logon = connection.getService(ILogon.class);
+ Future<?> result = logon.ping();
+ assertNull(result.get(0, TimeUnit.MILLISECONDS));
+ result = logon.logoff();
+ try {
+ result.get(0, TimeUnit.MICROSECONDS);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (ExecutionException e) {
+ assertTrue(e.getCause() instanceof MetaMatrixComponentException);
+ }
+ FakeService service = connection.getService(FakeService.class);
+ Future<Integer> asynchInteger = service.asynchResult();
+ assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
+ try {
+ service.exceptionMethod();
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (MetaMatrixProcessingException e) {
+
+ }
+ ClientSideDQP dqp = connection.getService(ClientSideDQP.class);
+ try {
+ dqp.begin();
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (XATransactionException e) {
+ e.printStackTrace();
+ assertEquals("Component not found: com.metamatrix.dqp.client.ClientSideDQP", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ private SocketServerConnection createFakeConnection(
+ final FakeClientServerInstance serverInstance)
+ throws CommunicationException, ConnectionException {
+ SocketServerConnection connection = new SocketServerConnection(new SocketServerInstanceFactory() {
+
+ @Override
+ public SocketServerInstance getServerInstance(HostInfo info,
+ boolean ssl) throws CommunicationException, IOException {
+ return serverInstance;
+ }
+
+ }, false, new UrlServerDiscovery(new MMURL("foo", 1, false)), new Properties(), null); //$NON-NLS-1$
+ return connection;
+ }
+
+}
Modified: trunk/engine/src/main/java/com/metamatrix/common/application/Application.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/application/Application.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/common/application/Application.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -34,6 +34,7 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.dqp.DQPPlugin;
+import com.metamatrix.dqp.ResourceFinder;
import com.metamatrix.dqp.service.DQPServiceNames;
import com.metamatrix.dqp.util.LogConstants;
@@ -43,37 +44,8 @@
protected ApplicationEnvironment environment = new ApplicationEnvironment();
private ArrayList<String> installedServices = new ArrayList<String>();
- private ServiceLoader loader = new ServiceLoader();
/*
- * @see com.metamatrix.common.application.Application#initialize(java.util.Properties)
- */
- public void start(DQPConfigSource configSource) throws ApplicationInitializationException {
- DQPGuiceModule module = new DQPGuiceModule(configSource);
-
- Injector injector = Guice.createInjector(module);
-
- // Load services into DQP
- for(int i=0; i<DQPServiceNames.ALL_SERVICES.length; i++) {
- final String serviceName = DQPServiceNames.ALL_SERVICES[i];
- final Class<? extends ApplicationService> type = DQPServiceNames.ALL_SERVICE_CLASSES[i];
- if(injector.getBinding(Key.get(type)) == null){
- LogManager.logInfo(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPLauncher.InstallService_ServiceIsNull", serviceName)); //$NON-NLS-1$
- }else{
- ApplicationService appService = injector.getInstance(type);
- appService = loader.loadService(serviceName, appService);
- String loggingContext = DQPServiceNames.SERVICE_LOGGING_CONTEXT[i];
- if (loggingContext != null) {
- appService = (ApplicationService)LogManager.createLoggingProxy(loggingContext, appService, new Class[] {type}, MessageLevel.DETAIL);
- }
- appService.initialize(configSource.getProperties());
- installService(serviceName, appService);
- LogManager.logInfo(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPLauncher.InstallService_ServiceInstalled", serviceName)); //$NON-NLS-1$
- }
- }
- }
-
- /*
* @see com.metamatrix.common.application.Application#installService(com.metamatrix.common.application.ApplicationService)
*/
public final void installService(String type, ApplicationService service) throws ApplicationInitializationException {
Modified: trunk/engine/src/main/java/com/metamatrix/common/application/DQPConfigSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/application/DQPConfigSource.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/common/application/DQPConfigSource.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -52,8 +52,5 @@
*/
public Properties getProperties();
- public Map<String, Class<? extends ApplicationService>> getDefaultServiceClasses();
-
- public void updateBindings(Binder binder);
-
+ public ApplicationService getServiceInstance(Class<? extends ApplicationService> type);
}
Deleted: trunk/engine/src/main/java/com/metamatrix/common/application/DQPGuiceModule.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/application/DQPGuiceModule.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/common/application/DQPGuiceModule.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.application;
-
-import java.util.Map;
-
-import com.google.inject.AbstractModule;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.dqp.service.DQPServiceNames;
-
-public class DQPGuiceModule extends AbstractModule {
-
- private DQPConfigSource configSource;
-
- public DQPGuiceModule(DQPConfigSource configSource) {
- this.configSource = configSource;
- }
-
- @Override
- protected void configure() {
- Map<String, Class<? extends ApplicationService>> defaults = configSource.getDefaultServiceClasses();
- for(int i=0; i<DQPServiceNames.ALL_SERVICES.length; i++) {
- final String serviceName = DQPServiceNames.ALL_SERVICES[i];
- String className = configSource.getProperties().getProperty("service."+serviceName+".classname"); //$NON-NLS-1$ //$NON-NLS-2$
- Class clazz = defaults.get(serviceName);
- if (clazz != null && className != null) {
- try {
- clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
- } catch (ClassNotFoundException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
- if (clazz != null) {
- bind(DQPServiceNames.ALL_SERVICE_CLASSES[i]).to(clazz);
- }
- }
-
- // inject the platform specific services.
- configSource.updateBindings(this.binder());
- }
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/storage/file/FileStorageManager.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/storage/file/FileStorageManager.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/storage/file/FileStorageManager.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -254,7 +254,7 @@
return baos.toByteArray();
} catch(IOException e) {
- throw new MetaMatrixComponentException(e, QueryExecPlugin.Util.getString("FileStoreageManager.batch_error")); //$NON-NLS-1$
+ throw new MetaMatrixComponentException(e, QueryExecPlugin.Util.getString("FileStorageManager.batch_error")); //$NON-NLS-1$
} finally {
if(oos != null) {
try {
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/AuditMessage.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/AuditMessage.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/AuditMessage.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -22,18 +22,8 @@
package com.metamatrix.dqp.service;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import com.metamatrix.common.config.CurrentConfiguration;
-
public class AuditMessage {
- public static final String PROCESS_NAME = CurrentConfiguration.getInstance().getProcessName();
- public static final String HOST_NAME = CurrentConfiguration.getInstance().getConfigurationName();
-
private static final String RESOURCE_DELIMITER = ", "; //$NON-NLS-1$
private String context;
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/AuthorizationService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/AuthorizationService.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/AuthorizationService.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -25,8 +25,10 @@
import java.util.Collection;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.security.AuthorizationMgmtException;
import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.core.CoreConstants;
+import com.metamatrix.platform.security.api.SessionToken;
import com.metamatrix.query.eval.SecurityFunctionEvaluator;
/**
@@ -48,6 +50,8 @@
public static final String DEFAULT_WSDL_USERNAME = CoreConstants.DEFAULT_ANON_USERNAME;
+ public static final String ENTITELEMENTS_ENABLED = "entitlements.enabled"; //$NON-NLS-1$
+
/**
* Determine which of a set of resources a connection does not have permission to
* perform the specified action.
@@ -65,4 +69,7 @@
* @return <code>true</code> iff server-side entitlements checking is enabled.
*/
boolean checkingEntitlements();
+
+ boolean isCallerInRole( SessionToken caller, String roleName ) throws AuthorizationMgmtException;
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -401,4 +401,6 @@
void clearClassLoaderCache() throws MetaMatrixComponentException;
boolean isFullyConfiguredVDB(VDBArchive vdb) throws MetaMatrixComponentException;
+
+ String getClusterName();
}
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/DQPServiceNames.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/DQPServiceNames.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/DQPServiceNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -23,6 +23,8 @@
package com.metamatrix.dqp.service;
import com.metamatrix.dqp.util.LogConstants;
+import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
/**
@@ -52,6 +54,11 @@
public static final String CONFIGURATION_SERVICE = "dqp.configuration"; //$NON-NLS-1$
public static final String REGISTRY_SERVICE = "platform.registry"; //$NON-NLS-1$
+
+ public static final String SESSION_SERVICE = "dqp.session"; //$NON-NLS-1$
+
+ public static final String MEMBERSHIP_SERVICE = "dqp.membership"; //$NON-NLS-1$
+
/**
* Array of all services a DQP may use.
@@ -64,6 +71,8 @@
VDB_SERVICE,
METADATA_SERVICE,
DATA_SERVICE,
+ SESSION_SERVICE,
+ MEMBERSHIP_SERVICE
};
public static final Class[] ALL_SERVICE_CLASSES = new Class[] {
@@ -74,6 +83,8 @@
VDBService.class,
MetadataService.class,
DataService.class,
+ SessionServiceInterface.class,
+ MembershipServiceInterface.class
};
public static final String[] SERVICE_LOGGING_CONTEXT = new String[] {
@@ -84,5 +95,7 @@
null,
null,
null,
+ null,
+ null
};
}
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/util/LogConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/util/LogConstants.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/util/LogConstants.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -32,4 +32,6 @@
public static final String CTX_EXTENSION_SOURCE = "EXTENSION_MODULE"; //$NON-NLS-1$
public static final String CTX_COMMANDLOGGING = "COMMAND_LOG"; //$NON-NLS-1$
public static final String CTX_AUDITLOGGING = "AUDIT_LOG"; //$NON-NLS-1$
+ public static final String CTX_ADMIN_API = "ADMIN_API"; //$NON-NLS-1$
+ public static final String CTX_QUERY_SERVICE = "QUERY_SERVICE"; //$NON-NLS-1$
}
Deleted: trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServiceInterface.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServiceInterface.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServiceInterface.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,504 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.platform.security.api.service;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.metamatrix.admin.api.exception.security.InvalidSessionException;
-import com.metamatrix.admin.api.exception.security.MetaMatrixSecurityException;
-import com.metamatrix.admin.api.objects.AdminOptions;
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.security.AuthorizationException;
-import com.metamatrix.api.exception.security.AuthorizationMgmtException;
-import com.metamatrix.api.exception.security.InvalidUserException;
-import com.metamatrix.api.exception.security.MembershipServiceException;
-import com.metamatrix.platform.admin.api.EntitlementMigrationReport;
-import com.metamatrix.platform.admin.api.PermissionDataNode;
-import com.metamatrix.platform.security.api.AuthorizationModel;
-import com.metamatrix.platform.security.api.AuthorizationPermission;
-import com.metamatrix.platform.security.api.AuthorizationPolicy;
-import com.metamatrix.platform.security.api.AuthorizationPolicyID;
-import com.metamatrix.platform.security.api.AuthorizationRealm;
-import com.metamatrix.platform.security.api.MetaMatrixPrincipalName;
-import com.metamatrix.platform.security.api.SessionToken;
-
-/**
- * This interface represents the API to the Authorization Service
- * and it defines the functionality that is accessible to clients.
- */
-public interface AuthorizationServiceInterface {
- public static String NAME = "AuthorizationService";
-
-
- /**
- * Return whether the specified account has authorization to access the specified resource.
- * This method returns false immediately upon encountering the first resource to which
- * the account does not have access.
- * @param sessionToken the session token of the principal whose access is being checked
- * @param contextName the name of the context for the caller (@see AuditContext)
- * @param request the permission that details the resource and the desired form of access
- * @return true if the specified principal is granted access to the requested resource,
- * or false otherwise
- * @throws InvalidSessionException if the session token for this cache is not valid
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation
- */
- boolean checkAccess( SessionToken sessionToken, String contextName, AuthorizationPermission request )
- throws InvalidSessionException, AuthorizationMgmtException;
-
- /**
- * Return whether the specified account has authorization to access the specified resource
- * and all its dependent resources.
- * This method returns false immediately upon encountering the first resource to which
- * the account does not have access.
- * @param sessionToken the session token of the principal whose access is being checked
- * @param contextName the name of the context for the caller (@see AuditContext)
- * @param request the permission that details the resource and the desired form of access
- * @param fetchDependants If <code>true</code>, search authorization store for all dependent
- * Permissions of the given request. Access is checked for <i>all</i> resources - the given
- * request and all dependents.
- * @return true if the specified principal is granted access to the requested resources,
- * or false otherwise
- * @throws InvalidSessionException if the session token for this cache is not valid
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation
- */
- boolean checkAccess( SessionToken sessionToken, String contextName, AuthorizationPermission request, boolean fetchDependants )
- throws InvalidSessionException, AuthorizationMgmtException;
-
- /**
- * Of those resources specified, return the subset for which the specified account does <i>not</i> have authorization
- * to access.
- * @param sessionToken the session token of the principal that is calling this method
- * @param contextName the name of the context for the caller (@see AuditContext)
- * @param requests the permissions that detail the resources and the desired form of access
- * @return the subset of <code>requests</code> that the account does <i>not</i> have access to
- * @throws InvalidSessionException if the session token for this cache is not valid
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation
- */
- Collection getInaccessibleResources( SessionToken sessionToken, String contextName, Collection requests )
- throws InvalidSessionException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>List</code> of entitlements to the given element pattern in the given realm.
- * <p>The list contains objects of type {@link com.metamatrix.platform.security.api.UserEntitlementInfo UserEntitlementInfo}
- * which will contain all user entitlement information for each element found. Each of these objects
- * will contain 1 or more objects of type {@link com.metamatrix.platform.security.api.GranteeEntitlementEntry GranteeEntitlementEntry}
- * which contain the <i>Grantee</i>'s name the entitlement <i>Grantor</i> or entity specifying the <i>Grantee</i>
- * is entitled and the <i>Allowed Actions</i> the <i>Grantee</i> is entitled to perform on the element.</p>
- * The attributes availible are:
- * <ol>
- * <li value=1>VDB Name</li>
- * <li>VDB Version</li>
- * <li>Group Name (fully qualified)</li>
- * <li>Element Name (fully qualified)</li>
- * <ul>
- * <li>Grantee Name; Grantor Name; Allowed Actions (A <code>String[]</code> of one or more of {CREATE, READ, UPDATE, DELETE})</li>
- * <li> ... </li>
- * </ul>
- * </ol>
- * @param realm The realm in which the element must live.
- * @param groupNames the fully qualified group names - the resources - for which to look up permissions.
- * Collection of <code>String</code>.
- * @return The <code>List</code> of entitlements to the given element in the
- * given realm - May be empty but never null.
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation.
- * @throws ServiceStateException if the Authorization service is not taking requests.
- */
- List getGroupEntitlements(AuthorizationRealm realm, Collection groupNames)
- throws AuthorizationMgmtException;
-
- /**
- * Returns a <code>List</code> of entitlements to the given element pattern in the given realm.
- * <p>The list contains objects of type {@link com.metamatrix.platform.security.api.UserEntitlementInfo UserEntitlementInfo}
- * which will contain all user entitlement information for each element found. Each of these objects
- * will contain 1 or more objects of type {@link com.metamatrix.platform.security.api.GranteeEntitlementEntry GranteeEntitlementEntry}
- * which contain the <i>Grantee</i>'s name the entitlement <i>Grantor</i> or entity specifying the <i>Grantee</i>
- * is entitled and the <i>Allowed Actions</i> the <i>Grantee</i> is entitled to perform on the element.</p>
- * The attributes availible are:
- * <ol>
- * <li value=1>VDB Name</li>
- * <li>VDB Version</li>
- * <li>Group Name (fully qualified)</li>
- * <li>Element Name (fully qualified)</li>
- * <ul>
- * <li>Grantee Name; Grantor Name; Allowed Actions (A <code>String[]</code> of one or more of {CREATE, READ, UPDATE, DELETE})</li>
- * <li> ... </li>
- * </ul>
- * </ol>
- * @param realm The realm in which the element must live.
- * @param fullyQualifiedGroupName The resource for which to look up permissions.
- * @return The <code>List</code> of entitlements to the given element in the
- * given realm - May be empty but never null.
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation.
- */
- List getGroupEntitlements(AuthorizationRealm realm, String fullyQualifiedGroupName)
- throws AuthorizationMgmtException;
-
- /**
- * Returns a <code>List</code> of entitlements to the given element pattern in the given realm.
- * <p>The list contains objects of type {@link com.metamatrix.platform.security.api.UserEntitlementInfo UserEntitlementInfo}
- * which will contain all user entitlement information for each element found. Each of these objects
- * will contain 1 or more objects of type {@link com.metamatrix.platform.security.api.GranteeEntitlementEntry GranteeEntitlementEntry}
- * which contain the <i>Grantee</i>'s name the entitlement <i>Grantor</i> or entity specifying the <i>Grantee</i>
- * is entitled and the <i>Allowed Actions</i> the <i>Grantee</i> is entitled to perform on the element.</p>
- * The attributes availible are:
- * <ol>
- * <li value=1>VDB Name</li>
- * <li>VDB Version</li>
- * <li>Group Name (fully qualified)</li>
- * <li>Element Name (fully qualified)</li>
- * <ul>
- * <li>Grantee Name; Grantor Name; Allowed Actions (A <code>String[]</code> of one or more of {CREATE, READ, UPDATE, DELETE})</li>
- * <li> ... </li>
- * </ul>
- * </ol>
- * @param realm The realm in which the element must live.
- * @param elementNames The fully qualified element resource for which to look up permissions. Collection of <code>String</code>.
- * @return The <code>List</code> of entitlements to the given element in the
- * given realm - May be empty but never null.
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation.
- */
- List getElementEntitlements(AuthorizationRealm realm, Collection elementNames)
- throws AuthorizationMgmtException;
-
- /**
- * Returns a <code>List</code> of entitlements to the given element pattern in the given realm.
- * <p>The list contains objects of type {@link com.metamatrix.platform.security.api.UserEntitlementInfo UserEntitlementInfo}
- * which will contain all user entitlement information for each element found. Each of these objects
- * will contain 1 or more objects of type {@link com.metamatrix.platform.security.api.GranteeEntitlementEntry GranteeEntitlementEntry}
- * which contain the <i>Grantee</i>'s name the entitlement <i>Grantor</i> or entity specifying the <i>Grantee</i>
- * is entitled and the <i>Allowed Actions</i> the <i>Grantee</i> is entitled to perform on the element.</p>
- * The attributes availible are:
- * <ol>
- * <li value=1>VDB Name</li>
- * <li>VDB Version</li>
- * <li>Group Name (fully qualified)</li>
- * <li>Element Name (fully qualified)</li>
- * <ul>
- * <li>Grantee Name; Grantor Name; Allowed Actions (A <code>String[]</code> of one or more of {CREATE, READ, UPDATE, DELETE})</li>
- * <li> ... </li>
- * </ul>
- * </ol>
- * @param realm The realm in which the element must live.
- * @param elementName The fully qualified element resource for which to look up permissions.
- * @return The <code>List</code> of entitlements to the given element in the
- * given realm - May be empty but never null.
- * @throws AuthorizationMgmtException if this service is unable to locate resources required
- * for this operation.
- */
- List getElementEntitlements(AuthorizationRealm realm, String elementName)
- throws AuthorizationMgmtException;
-
-////////////////////////////////////////////////////////////////////////////////
-// Admin methods
-////////////////////////////////////////////////////////////////////////////////
- /**
- * Obtain the names of all of the realms known to the system.
- * @param caller the session token of the principal that is attempting to access the realms.
- * @return the set of realm names
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- */
- Collection getRealmNames(SessionToken caller)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Return whether there is an existing policy with the specified ID.
- * @param caller the session token of the principal that is attempting to access the policies.
- * @param id the ID that is to be checked
- * @return true if a policy with the specified ID exists
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- * @see AuthorizationDomain.containsPolicy
- */
- boolean containsPolicy(SessionToken caller, AuthorizationPolicyID id )
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Locate the IDs of all of the policies that are accessible by the caller.
- * @param caller the session token of the principal that is attempting to access the policies.
- * @return the set of all policy IDs
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- * @see AuthorizationDomain.findAllPolicyIDs
- */
- Collection findAllPolicyIDs(SessionToken caller)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Locate the IDs of all of the policies that apply to the specified principal and that are accessible by the caller.
- * @param caller the session token of the principal that is attempting to access the policies.
- * @param principals the Set of UserGroupIDs and/or UserAccountIDs to whom the returned policies should apply to
- * (may not null, empty or invalid, all of which would result in an empty result)
- * @return the set of all policy IDs; never null but possibly empty
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- * @see AuthorizationModel.findAllPolicyIDs
- */
- Collection findPolicyIDs(SessionToken caller, Collection principals )
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Locate the policies that have the specified IDs. Any ID that is invalid is simply
- * ignored.
- * @param caller the session token of the principal that is attempting to access the
- * specified policies
- * @param policyIDs the policy IDs for which the policies are to be obtained
- * @return the set of entitlements that correspond to those specified IDs that are valid
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- * @see AuthorizationDomain.getPolicies
- */
- Collection getPolicies(SessionToken caller, Collection policyIDs)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Locate the policy that has the specified ID. Any ID that is invalid is simply
- * ignored.
- * @param caller the session token of the principal that is attempting to access the
- * specified policies
- * @param policyID the ID of the policy to be obtained
- * @return the policy that correspond to the specified ID
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- * @see AuthorizationDomain.getPolicy
- */
- AuthorizationPolicy getPolicy(SessionToken caller, AuthorizationPolicyID policyID)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Execute as a single transaction with the specified actions, and return
- * the set of IDs for the objects that were affected/modified by the action.
- * @param caller the session token of the principal that is attempting to access the policies.
- * @param actions the ordered list of actions that are to be performed
- * on metamodel within the repository.
- * @return The set of objects that were affected by this transaction.
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or has expired.
- * @throws AuthorizationException if the caller is unable to perform this operation.
- * @throws AuthorizationMgmtException if there were errors with the SPI. Causes rollback.
- * @throws IllegalArgumentException if the action is null.
- */
- Set executeTransaction(SessionToken caller, List actions)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Verify that caller is in the specified logical role.
- * @param caller The session token of the MetaMatrix principle involking an administrative method.
- * @return true if caller's session token is valid and he is a MetaMatrix administrator.
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- */
- boolean isCallerInRole( SessionToken caller, String roleName )
- throws AuthorizationMgmtException;
-
- /**
- * Obtain the names of all of the roles and their descriptions known to the system.
- * @param caller the session token of the principal that is attempting to access the roles.
- * @return a Map of role descriptions key by the role's name.
- * @throws InvalidSessionException if the <code>SessionToken</code> is not valid or is expired
- * @throws AuthorizationException if the caller is unable to perform this operation
- * @throws AuthorizationMgmtException if this service has trouble connecting to services it uses.
- */
- Map getRoleDescriptions(SessionToken caller)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a collection <code>MetaMatrixPrincipalName</code> objects containing the name
- * of the principal along with its type which belong to the given role.
- * {@link com.metamatrix.security.api.MetaMatrixPrincipalName}
- * @param caller the session token of the principal that is attempting to access the roles.
- * @param roleName String name of MetaMatrix role for which principals
- * are sought
- * @throws InvalidSessionException if the administrative session is invalid
- * @throws MetaMatrixSecurityException if there is a problem internally with the MembershipService
- * @throws AuthorizationException if administrator does not have the authority to see the requested information
- * @throws ComponentNotFoundException if a component required by this method could not be found within the server
- */
- Collection getPrincipalsForRole(SessionToken caller, String roleName)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a Collection of String names of MetaMatrix roles to which the
- * given principal is assigned.
- * @param caller the session token of the principal that is attempting to access the roles.
- * @param principal <code>MetaMatrixPrincipalName</code> for which roles are sought
- * @return The <code>Collection</code> of role names the principal is assigned.
- * @throws InvalidSessionException if the administrative session is invalid
- * @throws MetaMatrixSecurityException if there is a problem internally with the MembershipService
- * @throws AuthorizationException if administrator does not have the authority to see the requested information
- * @throws ComponentNotFoundException if a component required by this method could not be found within the server
- */
- Collection getRoleNamesForPrincipal(SessionToken caller, MetaMatrixPrincipalName principal)
- throws InvalidSessionException, AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Remove given Principal from <emph>ALL</emph> <code>AuthorizationPolicies</code> to
- * which he belongs.
- * @param caller the session token of the principal that is attempting to remove the Principal.
- * @param principal <code>MetaMatrixPrincipalName</code> which should be deleted.
- * @return true if at least one policy in which the principal had authorization
- * was found and deleted, false otherwise.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- boolean removePrincipalFromAllPolicies(SessionToken caller, MetaMatrixPrincipalName principal)
- throws AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>Collection</code> of <code>AuthorizationPolicyID</code>s
- * that have <code>AuthorizationPermission</code>s in the given <code>AuthorizationRealm</code>.<br>
- * <strong>NOTE:</strong> It is the responsibility of the caller to determine
- * which of the <code>AuthorizationPolicy</code>'s <code>AuthorizationPermission</code>s
- * are actually in the given <code>AuthorizationRealm</code>. The <code>AuthorizationPolicy</code>
- * may span <code>AuthorizationRealm</code>s.
- * @param caller The session token of the principal that is attempting to retrieve the policies.
- * @param realm The realm in which to search for <code>AuthorizationPermission</code>s.
- * @return The collection of <code>AuthorizationPolicyID</code>s that have permissions
- * in the given realm - possibly empty but never null.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- Collection getPolicyIDsWithPermissionsInRealm(SessionToken caller, AuthorizationRealm realm)
- throws AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>Collection</code> of <code>AuthorizationPolicyID</code>s
- * in the given <code>AuthorizationRealm</code>.
- * <br>This method will only work for Data Access Authorizations because the realm
- * is encoded in a Data Access policy name.
- * <strong>NOTE:</strong> It is the responsibility of the caller to determine
- * which of the <code>AuthorizationPolicy</code>'s <code>AuthorizationPermission</code>s
- * are actually in the given <code>AuthorizationRealm</code>. The <code>AuthorizationPolicy</code>
- * may span <code>AuthorizationRealm</code>s.
- * @param caller The session token of the principal that is attempting to retrieve the policies.
- * @param realm The realm in which to search for <code>AuthorizationPermission</code>s.
- * @return The collection of <code>AuthorizationPolicyID</code>s that have permissions
- * in the given realm - possibly empty but never null.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- Collection getPolicyIDsInRealm(SessionToken caller, AuthorizationRealm realm)
- throws AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>Collection</code> of <code>AuthorizationPolicy</code>s
- * that have <code>AuthorizationPermission</code>s in the given <code>AuthorizationRealm</code>.<br>
- * <strong>NOTE:</strong> It is the responsibility of the caller to determine
- * which of the <code>AuthorizationPolicy</code>'s <code>AuthorizationPermission</code>s
- * are actually in the given <code>AuthorizationRealm</code>. The <code>AuthorizationPolicy</code>
- * may span <code>AuthorizationRealm</code>s.
- * @param caller The session token of the principal that is attempting to retrieve the policies.
- * @param realm The realm in which to search for <code>AuthorizationPermission</code>s.
- * @return The collection of <code>AuthorizationPolicy</code>s that have permissions
- * in the given realm - possibly empty but never null.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- Collection getPoliciesInRealm(SessionToken caller, AuthorizationRealm realm)
- throws AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>Collection</code> of <code>AuthorizationPolicyID</code>s
- * that have <code>AuthorizationPermissions</code> that exist in the given
- * <emph>partial</emph> <code>AuthorizationRealm</code>.<br>
- * The implementation is such that all <code>AuthorizationPolicyID</code>s
- * whose <code>AuthorizationRealm</code> <emph>starts with</emph> the given
- * <code>AuthorizationRealm</code> are returned.
- * @param caller The session token of the principal that is attempting to retrieve the policies.
- * @param realm The <emph>partial</emph> realm in which to search for
- * <code>AuthorizationPermission</code>s whose realm name <emph>starts with</emph>
- * the given realm.
- * @return The collection of <code>AuthorizationPolicyID</code>s that have permissions
- * in the given partial realm - possibly empty but never null.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- public Collection getPolicyIDsInPartialRealm(SessionToken caller, AuthorizationRealm realm)
- throws AuthorizationException, AuthorizationMgmtException;
-
- /**
- * Returns a <code>Collection</code> of <code>AuthorizationPolicyID</code>s
- * that have <code>AuthorizationPermissions</code> on the given resource that
- * exists in the given <code>AuthorizationRealm</code>.<br>
- * @param caller The session token of the principal that is attempting to retrieve the policies.
- * @param realm The realm in which to search for <code>AuthorizationPermission</code>s.
- * @param resourceName The resource for which to search for <code>AuthorizationPermission</code>s.
- * @return The collection of <code>AuthorizationPolicyID</code>s that have permissions
- * on the given resource - possibly empty but never null.
- * @throws AuthorizationException if administrator does not have the authority to perform the action.
- * @throws AuthorizationMgmtException if an error occurs in the Authorization store.
- */
- Collection getPolicIDsForResourceInRealm(SessionToken caller, AuthorizationRealm realm, String resourceName)
- throws AuthorizationException, AuthorizationMgmtException;
-
- public boolean hasPolicy(SessionToken caller, AuthorizationRealm realm, String policyName)
- throws AuthorizationMgmtException, InvalidUserException, MembershipServiceException;
-
-
- public void migratePolicies(SessionToken token,
- EntitlementMigrationReport rpt,
- String targetVDBName, String targetVDBVersion, Set targetNodes,
- Collection sourcePolicies, AdminOptions options) throws MetaMatrixComponentException,
- InvalidSessionException,
- AuthorizationException,
- AuthorizationMgmtException;
-
- /**
- * Takes a tree of <code>PermissionDataNodeImpl</code>s that have their <code>Resource</code>s
- * filled in and fills in all permissions on resources that are found in the given
- * <code>AuthorizationPolicyID</code>.<br></br>
- * If any permissions are found that have no corresponding data node, a <code>AuthorizationMgmtException</code>
- * is thrown noting the missing resource name(s).
- * @param root The node containing the resource (group or element full name)
- * for which to search for permission(s).
- * @param realm The realm in which to search.
- * @param tree The tree of PermissionDataNodes to fill in permissions for.
- * @return The root of the filled in tree.
- * If no permissions exist, the original is returned as the sole element in the list.
- * @throws AuthorizationMgmtException if there is a connection or communication error with the data source,
- * signifying that the method should be retried with a different connection; if there is an
- * unspecified or unknown error with the data source; or one or more permissions were found but
- * a corresponding <code>PermissionDataNodeImpl</code> could not be found.
- */
- PermissionDataNode fillPermissionNodeTree(PermissionDataNode root, AuthorizationPolicyID policyID)
- throws AuthorizationMgmtException;
-}
-
-
-
-
-
Deleted: trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServicePropertyNames.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServicePropertyNames.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/AuthorizationServicePropertyNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.platform.security.api.service;
-
-public class AuthorizationServicePropertyNames {
-
- /**
- * The environment property the determines whether data access authorization will
- * be performed.
- * <br> This property defaults to "false" - no entitlement checking.</br>
- */
- public static final String DATA_ACCESS_AUTHORIZATION_ENABLED = "metamatrix.authorization.dataaccess.CheckingEnabled"; //$NON-NLS-1$
-
- /**
- * The environment property the determines whether MetaBase authorization will
- * be performed.
- * <br> This property defaults to "false" - no entitlement checking.</br>
- */
- public static final String METABASE_AUTHORIZATION_ENABLED = "metamatrix.authorization.metabase.CheckingEnabled"; //$NON-NLS-1$
-
- /**
- * The environment property name for the class that is to be used for the ManagedConnectionFactory implementation.
- * This property is required (there is no default).
- */
- public static final String CONNECTION_FACTORY = "security.authorization.connection.Factory"; //$NON-NLS-1$
-
- /**
- * The environment property name for the number of times a method should be retried
- * with a new connection should a connection exception occur.
- * This property is optional.
- */
- public static final String CONNECTION_RETRIES = "security.authorization.connection.Retries"; //$NON-NLS-1$
-
- /**
- * The environment property name for the class of the driver.
- * This property is optional.
- */
- public static final String CONNECTION_DRIVER = "security.authorization.connection.Driver"; //$NON-NLS-1$
-
- /**
- * The environment property name for the protocol for connecting to the authorization store.
- * This property is optional.
- */
- public static final String CONNECTION_PROTOCOL = "security.authorization.connection.Protocol"; //$NON-NLS-1$
-
- /**
- * The environment property name for the name of the authorization store database.
- * This property is optional.
- */
- public static final String CONNECTION_DATABASE = "security.authorization.connection.Database"; //$NON-NLS-1$
-
- /**
- * The environment property name for the username that is to be used for connecting to the authorization store.
- * This property is optional.
- */
- public static final String CONNECTION_PRINCIPAL = "security.authorization.connection.Principal"; //$NON-NLS-1$
-
- /**
- * The environment property name for the password that is to be used for connecting to the authorization store.
- * This property is optional.
- */
- public static final String CONNECTION_PASSWORD = "security.authorization.connection.Password"; //$NON-NLS-1$
-
- /**
- * The environment property name for the maximum number of milliseconds that a authorization connection
- * may remain unused before it becomes a candidate for garbage collection.
- * This property is optional.
- */
- public static final String CONNECTION_POOL_MAXIMUM_AGE = "security.authorization.connection.MaximumAge"; //$NON-NLS-1$
-
- /**
- * The environment property name for the maximum number of concurrent users of a single authorization connection.
- * This property is optional.
- */
- public static final String CONNECTION_POOL_MAXIMUM_CONCURRENT_USERS = "security.authorization.connection.MaximumConcurrentReaders"; //$NON-NLS-1$
-
- /**
- * The default authorization factory class when no class is specified.
- */
- public static final String DEFAULT_FACTORY_CLASS="com.metamatrix.platform.security.authorization.spi.jdbc.JDBCAuthorizationTransactionFactory";
-
-}
-
Modified: trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/MembershipServiceInterface.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/MembershipServiceInterface.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/MembershipServiceInterface.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -30,8 +30,6 @@
import com.metamatrix.api.exception.security.InvalidPrincipalException;
import com.metamatrix.api.exception.security.MembershipServiceException;
import com.metamatrix.common.application.ApplicationService;
-import com.metamatrix.common.config.ResourceNames;
-import com.metamatrix.common.config.util.ConfigurationPropertyNames;
import com.metamatrix.core.CoreConstants;
import com.metamatrix.platform.security.api.Credentials;
import com.metamatrix.platform.security.api.MetaMatrixPrincipal;
@@ -42,7 +40,7 @@
* and it defines the functionality that is accessible to clients.
*/
public interface MembershipServiceInterface extends ApplicationService {
- public static String NAME = ResourceNames.MEMBERSHIP_SERVICE;
+ public static String NAME = "MembershipService"; //$NON-NLS-1$
/**
* The environment property describing both the domain names and their required
@@ -50,21 +48,21 @@
* and in the form "A,X,...,D" where A, X and D are domain names.
* This property is required (there is no default).
*/
- public static final String DOMAIN_ORDER = ConfigurationPropertyNames.MEMBERSHIP_DOMAIN_ORDER;
+ public static final String DOMAIN_ORDER = "membership.DomainOrder"; //$NON-NLS-1$
/**
* The environment property name for the class that is to be used for the names of the domains.
* This property is required (there is no default).
*/
public static final String DOMAIN_NAME = "domainName"; //$NON-NLS-1$
- public static final String DEFAULT_ADMIN_USERNAME = "metamatrixadmin"; //$NON-NLS-1$
+ public static final String DEFAULT_ADMIN_USERNAME = "admin"; //$NON-NLS-1$
public static final String DEFAULT_WSDL_USERNAME = CoreConstants.DEFAULT_ANON_USERNAME;
- public static final String ADMIN_PASSWORD = ConfigurationPropertyNames.MEMBERSHIP_ADMIN_PASSWORD;
- public static final String ADMIN_USERNAME = ConfigurationPropertyNames.MEMBERSHIP_ADMIN_USERNAME;
+ public static final String ADMIN_PASSWORD = "membership.superUserPassword"; //$NON-NLS-1$
+ public static final String ADMIN_USERNAME = "membership.superUser"; //$NON-NLS-1$
public static final String DOMAIN_ACTIVE = "activate"; //$NON-NLS-1$
- public static final String ADMIN_HOSTS = "metamatrix.security.admin.allowedHosts"; //$NON-NLS-1$
- public static final String SECURITY_ENABLED = ConfigurationPropertyNames.MEMBERSHIP_SECURITY_ENABLED;
+ public static final String ADMIN_HOSTS = "membership.allowedHosts"; //$NON-NLS-1$
+ public static final String SECURITY_ENABLED = "membership.enabled"; //$NON-NLS-1$
public static final String DOMAIN_PROPERTIES = "propertiesFile"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -56,7 +56,13 @@
*/
public interface SessionServiceInterface extends ApplicationService {
public static String NAME = "SessionService"; //$NON-NLS-1$
+
+ public static final String DEFAULT_MAX_SESSIONS = "5000"; //$NON-NLS-1$
+ public static final String DEFAULT_SESSION_TIMEOUT = "600000"; //$NON-NLS-1$
+ public static final String MAX_SESSIONS = "session.maxSessions"; //$NON-NLS-1$
+ public static final String SESSION_TIMEOUT = "session.timeoutInMilli"; //$NON-NLS-1$
+
/**
* Create a session for the given user authenticating against the given <code>Credentials</code>.
*/
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -44,12 +44,17 @@
import org.teiid.dqp.internal.cache.ResultSetCache;
import org.teiid.dqp.internal.cache.ResultSetCacheUtil;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Singleton;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.common.application.Application;
import com.metamatrix.common.application.ApplicationEnvironment;
+import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.common.application.DQPConfigSource;
+import com.metamatrix.common.application.ServiceLoader;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
import com.metamatrix.common.buffer.BufferManager;
@@ -93,6 +98,7 @@
/**
* Implements the core DQP processing.
*/
+@Singleton
public class DQPCore extends Application implements ClientSideDQP {
static class ConnectorCapabilitiesCache {
@@ -149,15 +155,8 @@
private Map<RequestID, RequestWorkItem> requests = Collections.synchronizedMap(new HashMap<RequestID, RequestWorkItem>());
private Map<String, List<RequestID>> requestsByClients = Collections.synchronizedMap(new HashMap<String, List<RequestID>>());
private DQPContextCache contextCache;
-
- public DQPCore() {
-
- }
-
- public DQPCore(ApplicationEnvironment environment) {
- this.environment = environment;
- }
-
+ private ServiceLoader loader = new ServiceLoader();
+
/**
* perform a graceful shutdown by allowing in process work to complete
* TODO: this is not quite correct from a request perspective, since we need to re-queue in many instances,
@@ -584,17 +583,43 @@
return chunkSize;
}
- @Override
- public void start(DQPConfigSource configSource)
- throws ApplicationInitializationException {
- super.start(configSource);
+
+ /*
+ * @see com.metamatrix.common.application.Application#initialize(java.util.Properties)
+ */
+ public void start(DQPConfigSource configSource) throws ApplicationInitializationException {
+
+ // Load services into DQP
+ for(int i=0; i<DQPServiceNames.ALL_SERVICES.length; i++) {
+
+ final String serviceName = DQPServiceNames.ALL_SERVICES[i];
+ final Class<? extends ApplicationService> type = DQPServiceNames.ALL_SERVICE_CLASSES[i];
+
+ ApplicationService appService = configSource.getServiceInstance(type);
+ if (appService == null) {
+ LogManager.logInfo(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPLauncher.InstallService_ServiceIsNull", serviceName)); //$NON-NLS-1$
+ continue;
+ }
+
+ appService = loader.loadService(serviceName, appService);
+ String loggingContext = DQPServiceNames.SERVICE_LOGGING_CONTEXT[i];
+ if (loggingContext != null) {
+ appService = (ApplicationService)LogManager.createLoggingProxy(loggingContext, appService, new Class[] {type}, MessageLevel.DETAIL);
+ }
+
+ appService.initialize(configSource.getProperties());
+ installService(serviceName, appService);
+ LogManager.logInfo(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPLauncher.InstallService_ServiceInstalled", serviceName)); //$NON-NLS-1$
+ }
+
ConfigurationService cs = (ConfigurationService)this.getEnvironment().findService(DQPServiceNames.CONFIGURATION_SERVICE);
Properties p = configSource.getProperties();
if (cs != null) {
p = cs.getSystemProperties();
}
start(p);
- }
+ }
+
public void start(Properties props) {
ApplicationEnvironment env = this.getEnvironment();
Modified: trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties 2009-06-26 22:06:04 UTC (rev 1088)
@@ -206,5 +206,5 @@
FileStoreageManager.no_directory=No directory specified for the file storage manager.
FileStoreageManager.not_a_directory={0} is not a valid storage manager directory.
FileStorageManager.error_getting_free_disk_space=Error while seeking free disk space for directory: {0}
-FileStorageManager.can_not_save_lobs=Can not save *Reference Lobs* into peristent disk storage.
-
+FileStorageManager.can_not_save_lobs=Can not save *Reference Lobs* into persistent disk storage.
+FileStorageManager.batch_error=Error while converting batched data to file storage.
Modified: trunk/engine/src/test/java/com/metamatrix/dqp/config/TestDQPLauncher.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/config/TestDQPLauncher.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/config/TestDQPLauncher.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -33,10 +33,13 @@
import com.metamatrix.common.application.ApplicationService;
import com.metamatrix.common.application.DQPConfigSource;
import com.metamatrix.dqp.service.AutoGenDataService;
+import com.metamatrix.dqp.service.BufferService;
import com.metamatrix.dqp.service.DQPServiceNames;
+import com.metamatrix.dqp.service.DataService;
import com.metamatrix.dqp.service.FakeAbstractService;
import com.metamatrix.dqp.service.FakeBufferService;
import com.metamatrix.dqp.service.FakeMetadataService;
+import com.metamatrix.dqp.service.MetadataService;
/**
*/
@@ -53,19 +56,17 @@
public void testLaunch() throws Exception {
DQPConfigSource configSource = Mockito.mock(DQPConfigSource.class);
Mockito.stub(configSource.getProperties()).toReturn(new Properties());
- HashMap<String, Class<? extends ApplicationService>> defaults = new HashMap<String, Class<? extends ApplicationService>>();
- Mockito.stub(configSource.getDefaultServiceClasses()).toReturn(defaults);
+
String[] services = new String[] {DQPServiceNames.BUFFER_SERVICE, DQPServiceNames.METADATA_SERVICE, DQPServiceNames.DATA_SERVICE};
- defaults.put(DQPServiceNames.BUFFER_SERVICE, FakeBufferService.class);
- defaults.put(DQPServiceNames.METADATA_SERVICE, FakeMetadataService.class);
- defaults.put(DQPServiceNames.DATA_SERVICE, AutoGenDataService.class);
+ Mockito.stub(configSource.getServiceInstance(BufferService.class)).toReturn(new FakeBufferService());
+ Mockito.stub(configSource.getServiceInstance(MetadataService.class)).toReturn(new FakeMetadataService());
+ Mockito.stub(configSource.getServiceInstance(DataService.class)).toReturn(new AutoGenDataService());
+
DQPCore dqpCore = new DQPCore();
dqpCore.start(configSource);
- DQPCore dqp = new DQPCore();
- dqp.start(configSource);
- assertNotNull("DQP should not be null", dqp); //$NON-NLS-1$
+ assertNotNull("DQP should not be null", dqpCore); //$NON-NLS-1$
// Check that bootstrapping occurred
for(int i=0; i<services.length; i++) {
Modified: trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeAuthorizationService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeAuthorizationService.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeAuthorizationService.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -25,9 +25,11 @@
import java.util.*;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.security.AuthorizationMgmtException;
import com.metamatrix.common.application.ApplicationEnvironment;
import com.metamatrix.common.application.exception.ApplicationInitializationException;
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
+import com.metamatrix.platform.security.api.SessionToken;
/**
*/
@@ -154,4 +156,11 @@
String roleName) throws MetaMatrixComponentException {
return false;
}
+
+ @Override
+ public boolean isCallerInRole(SessionToken caller, String roleName)
+ throws AuthorizationMgmtException {
+ // rameshTODO Auto-generated method stub
+ return false;
+ }
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -74,7 +74,7 @@
String vdbName = "bqt"; //$NON-NLS-1$
String vdbVersion = "1"; //$NON-NLS-1$
- ApplicationEnvironment env = new ApplicationEnvironment();
+ final ApplicationEnvironment env = new ApplicationEnvironment();
env.bindService(DQPServiceNames.BUFFER_SERVICE, new FakeBufferService());
FakeMetadataService mdSvc = new FakeMetadataService();
mdSvc.addVdb(vdbName, vdbVersion, FakeMetadataFactory.exampleBQTCached());
@@ -88,7 +88,11 @@
vdbService.addModel(vdbName, vdbVersion, "BQT3", ModelInfo.PRIVATE, false); //$NON-NLS-1$
env.bindService(DQPServiceNames.VDB_SERVICE, vdbService);
- core = new DQPCore(env);
+ core = new DQPCore() {
+ public ApplicationEnvironment getEnvironment() {
+ return env;
+ }
+ };
core.start(new Properties());
}
Modified: trunk/server/pom.xml
===================================================================
--- trunk/server/pom.xml 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/pom.xml 2009-06-26 22:06:04 UTC (rev 1088)
@@ -55,6 +55,11 @@
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-txn-jbossts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-embedded</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-common-core</artifactId>
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -40,6 +40,8 @@
import java.util.Set;
import java.util.StringTokenizer;
+import org.teiid.transport.SSLConfiguration;
+
import com.metamatrix.admin.AdminPlugin;
import com.metamatrix.admin.api.exception.AdminComponentException;
import com.metamatrix.admin.api.exception.AdminException;
@@ -102,7 +104,6 @@
import com.metamatrix.common.extensionmodule.exception.ExtensionModuleNotFoundException;
import com.metamatrix.common.extensionmodule.exception.InvalidExtensionModuleTypeException;
import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.net.ServerSocketConfiguration;
import com.metamatrix.common.util.LogContextsUtil;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.util.crypto.CryptoException;
@@ -813,7 +814,8 @@
ProcessObject hostProcess = (ProcessObject) hostProcesses.iterator().next();
mmPort = hostProcess.getPropertyValue(ProcessObject.SERVER_PORT);
- boolean useSSL = ServerSocketConfiguration.isSSLEnabled();
+ //boolean useSSL = SSLConfiguration.isSSLEnabled();
+ boolean useSSL = false;
String mmDriver = "com.metamatrix.jdbc.MMDriver"; //$NON-NLS-1$
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/ChannelListener.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/ChannelListener.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/ChannelListener.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket;
-
-import com.metamatrix.common.comm.exception.CommunicationException;
-
-public interface ChannelListener {
-
- public interface ChannelListenerFactory {
- ChannelListener createChannelListener(ObjectChannel channel);
- }
-
- void receivedMessage(Object msg) throws CommunicationException;
-
- void exceptionOccurred(Throwable t);
-
- void onConnection() throws CommunicationException;
-}
\ No newline at end of file
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SSLAwareChannelHandler.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SSLAwareChannelHandler.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SSLAwareChannelHandler.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,250 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/**
- *
- */
-package com.metamatrix.common.comm.platform.socket;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicLong;
-
-import javax.net.ssl.SSLEngine;
-
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.ChannelFutureListener;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineCoverage;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.DefaultChannelPipeline;
-import org.jboss.netty.channel.ExceptionEvent;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.codec.serialization.ObjectDecoder;
-import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
-import org.jboss.netty.handler.ssl.SslHandler;
-
-import com.metamatrix.common.comm.exception.SingleInstanceCommunicationException;
-import com.metamatrix.common.comm.platform.CommPlatformPlugin;
-
-/**
- * Main class for creating Netty Nio Channels
- */
-
-(a)ChannelPipelineCoverage(ChannelPipelineCoverage.ALL)
-public class SSLAwareChannelHandler extends SimpleChannelHandler implements ChannelPipelineFactory {
-
- public class ObjectChannelImpl implements ObjectChannel {
- private final Channel channel;
-
- public ObjectChannelImpl(Channel channel) {
- this.channel = channel;
- }
-
- public void close() {
- channel.close();
- }
-
- public boolean isOpen() {
- return channel.isOpen();
- }
-
- public SocketAddress getRemoteAddress() {
- return channel.getRemoteAddress();
- }
-
- @Override
- public Object read() throws IOException,
- ClassNotFoundException {
- throw new UnsupportedOperationException();
- }
-
- public Future<?> write(Object msg) {
- final ChannelFuture future = channel.write(msg);
- future.addListener(completionListener);
- return new Future<Void>() {
-
- @Override
- public boolean cancel(boolean arg0) {
- return future.cancel();
- }
-
- @Override
- public Void get() throws InterruptedException,
- ExecutionException {
- future.await();
- if (!future.isSuccess()) {
- throw new ExecutionException(future.getCause());
- }
- return null;
- }
-
- @Override
- public Void get(long arg0, TimeUnit arg1)
- throws InterruptedException, ExecutionException,
- TimeoutException {
- if (future.await(arg0, arg1)) {
- if (!future.isSuccess()) {
- throw new ExecutionException(future.getCause());
- }
- return null;
- }
- throw new TimeoutException();
- }
-
- @Override
- public boolean isCancelled() {
- return future.isCancelled();
- }
-
- @Override
- public boolean isDone() {
- return future.isDone();
- }
- };
- }
- }
-
- private final ChannelListener.ChannelListenerFactory listenerFactory;
- private final SSLEngine engine;
- private final ClassLoader classLoader;
- private Map<Channel, ChannelListener> listeners = Collections.synchronizedMap(new HashMap<Channel, ChannelListener>());
- private AtomicLong objectsRead = new AtomicLong(0);
- private AtomicLong objectsWritten = new AtomicLong(0);
- private volatile int maxChannels;
-
- private ChannelFutureListener completionListener = new ChannelFutureListener() {
-
- @Override
- public void operationComplete(ChannelFuture arg0)
- throws Exception {
- if (arg0.isSuccess()) {
- objectsWritten.getAndIncrement();
- }
- }
-
- };
-
- public SSLAwareChannelHandler(ChannelListener.ChannelListenerFactory listenerFactory,
- SSLEngine engine, ClassLoader classloader) {
- this.listenerFactory = listenerFactory;
- this.engine = engine;
- this.classLoader = classloader;
- }
-
- @Override
- public void channelConnected(ChannelHandlerContext ctx,
- final ChannelStateEvent e) throws Exception {
- ChannelListener listener = this.listenerFactory.createChannelListener(new ObjectChannelImpl(e.getChannel()));
- synchronized (this.listeners) {
- this.listeners.put(e.getChannel(), listener);
- maxChannels = Math.max(maxChannels, this.listeners.size());
- }
- if (engine != null) {
- SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
- sslHandler.handshake(e.getChannel()).addListener(new ChannelFutureListener() {
- public void operationComplete(ChannelFuture arg0)
- throws Exception {
- onConnection(e.getChannel());
- }
- });
- } else {
- onConnection(e.getChannel());
- }
- }
-
- private void onConnection(Channel channel) throws Exception {
- ChannelListener listener = this.listeners.get(channel);
- if (listener != null) {
- listener.onConnection();
- }
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx,
- ExceptionEvent e) throws Exception {
- ChannelListener listener = this.listeners.get(e.getChannel());
- if (listener != null) {
- listener.exceptionOccurred(e.getCause());
- }
- e.getChannel().close();
- }
-
- @Override
- public void messageReceived(ChannelHandlerContext ctx,
- MessageEvent e) throws Exception {
- objectsRead.getAndIncrement();
- ChannelListener listener = this.listeners.get(e.getChannel());
- if (listener != null) {
- listener.receivedMessage(e.getMessage());
- }
- }
-
- @Override
- public void channelDisconnected(ChannelHandlerContext ctx,
- ChannelStateEvent e) throws Exception {
- ChannelListener listener = this.listeners.remove(e.getChannel());
- if (listener != null) {
- listener.exceptionOccurred(new SingleInstanceCommunicationException(CommPlatformPlugin.Util.getString("SSLAwareChannelHandler.channel_closed"))); //$NON-NLS-1$
- }
- }
-
- public ChannelPipeline getPipeline() throws Exception {
- ChannelPipeline pipeline = new DefaultChannelPipeline();
-
- if (engine != null) {
- pipeline.addLast("ssl", new SslHandler(engine)); //$NON-NLS-1$
- }
- pipeline.addLast("decoder", new ObjectDecoder(1 << 24, classLoader)); //$NON-NLS-1$
- pipeline.addLast("encoder", new ObjectEncoder()); //$NON-NLS-1$
- pipeline.addLast("handler", this); //$NON-NLS-1$
- return pipeline;
- }
-
- public long getObjectsRead() {
- return this.objectsRead.get();
- }
-
- public long getObjectsWritten() {
- return this.objectsWritten.get();
- }
-
- public int getConnectedChannels() {
- return this.listeners.size();
- }
-
- public int getMaxConnectedChannels() {
- return this.maxChannels;
- }
-
-}
\ No newline at end of file
Modified: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -24,17 +24,18 @@
import java.util.Properties;
+import org.teiid.transport.SSLConfiguration;
+import org.teiid.transport.SocketListener;
+
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.comm.platform.socket.server.SocketListener;
import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.api.Host;
import com.metamatrix.common.config.api.VMComponentDefnType;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.messaging.MessageBus;
-import com.metamatrix.common.net.ServerSocketConfiguration;
import com.metamatrix.common.queue.WorkerPoolStats;
import com.metamatrix.common.util.LogCommonConstants;
import com.metamatrix.common.util.PropertiesUtils;
@@ -120,9 +121,9 @@
};
logMessage(PlatformPlugin.Util.getString("SocketVMController.1", param)); //$NON-NLS-1$
- ServerSocketConfiguration helper = new ServerSocketConfiguration();
+ SSLConfiguration helper = new SSLConfiguration();
try {
- helper.init();
+ helper.init(props);
listener = new SocketListener(socketPort, bindaddress, this.clientServices, inputBufferSize, outputBufferSize, maxThreads, helper.getServerSSLEngine(), helper.isClientEncryptionEnabled(), PlatformProxyHelper.getSessionServiceProxy(PlatformProxyHelper.ROUND_ROBIN_LOCAL));
} catch (Exception e) {
LogManager.logCritical(LogCommonConstants.CTX_CONTROLLER, e, PlatformPlugin.Util.getString("SocketVMController.2",param)); //$NON-NLS-1$
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/AdminAuthorizationInterceptor.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/AdminAuthorizationInterceptor.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/AdminAuthorizationInterceptor.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,145 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import org.teiid.dqp.internal.process.DQPWorkContext;
-
-import com.metamatrix.admin.RolesAllowed;
-import com.metamatrix.admin.api.server.AdminRoles;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.security.AuthorizationException;
-import com.metamatrix.client.ExceptionUtil;
-import com.metamatrix.common.comm.platform.CommPlatformPlugin;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.util.LogContextsUtil;
-import com.metamatrix.common.util.LogContextsUtil.PlatformAdminConstants;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.log.MessageLevel;
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.dqp.service.AuditMessage;
-import com.metamatrix.platform.security.api.SessionToken;
-import com.metamatrix.platform.security.api.service.AuthorizationServiceInterface;
-import com.metamatrix.platform.security.audit.AuditManager;
-
-/**
- * Call authorization service to make sure the current admin user has the
- * proper admin role(s) to perform the method.
- */
-public class AdminAuthorizationInterceptor implements InvocationHandler {
-
- private final Object service;
- private AuthorizationServiceInterface authAdmin;
-
-
- /**
- * Ctor.
- * @param securityContextFactory
- * @param authorizationService
- * @param methodNames
- * @since 4.3
- */
- public AdminAuthorizationInterceptor(
- AuthorizationServiceInterface authorizationService, Object service) {
- ArgCheck.isNotNull(authorizationService);
- this.authAdmin = authorizationService;
- this.service = service;
- }
-
- /**
- *
- * @param invocation
- * @param securityContext
- * @throws AuthorizationException
- * @throws MetaMatrixProcessingException
- * @since 4.3
- */
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- SessionToken adminToken = DQPWorkContext.getWorkContext().getSessionToken();
-
- Method serviceMethod = service.getClass().getMethod(method.getName(), method.getParameterTypes());
- RolesAllowed allowed = serviceMethod.getAnnotation(RolesAllowed.class);
- if (allowed == null) {
- allowed = method.getAnnotation(RolesAllowed.class);
- if (allowed == null) {
- allowed = serviceMethod.getDeclaringClass().getAnnotation(RolesAllowed.class);
- if (allowed == null) {
- allowed = method.getDeclaringClass().getAnnotation(RolesAllowed.class);
- }
- }
- }
- if (allowed == null || allowed.value() == null) {
- throw new MetaMatrixRuntimeException("Could not determine roles allowed for admin method"); //$NON-NLS-1$
- }
-
- boolean authorized = false;
- AuditMessage msg = new AuditMessage(PlatformAdminConstants.CTX_ADMIN_API, Arrays.toString(allowed.value())+"-request", adminToken.getUsername(), new Object[]{method.getName()}); //$NON-NLS-1$
- LogManager.log(MessageLevel.INFO, LogContextsUtil.CommonConstants.CTX_AUDITLOGGING, msg);
-
- for (int i = 0; i < allowed.value().length; i++) {
- String requiredRoleName = allowed.value()[i];
- if (AdminRoles.RoleName.ANONYMOUS.equalsIgnoreCase(requiredRoleName)) {
- authorized = true;
- break;
- }
-
- if (authAdmin.isCallerInRole(adminToken, requiredRoleName)) {
- authorized = true;
- break;
- }
- }
- if (!authorized) {
- msg = new AuditMessage(PlatformAdminConstants.CTX_ADMIN_API, Arrays.toString(allowed.value())+"-denied", adminToken.getUsername(), new Object[]{method.getName()}); //$NON-NLS-1$
- LogManager.log(MessageLevel.INFO, LogContextsUtil.CommonConstants.CTX_AUDITLOGGING, msg);
-
- Object[] msgParts = buildAuditMessage(adminToken, Arrays.toString(allowed.value()), method);
- String errMsg = CommPlatformPlugin.Util.getString("AdminAuthorizationInterceptor.Admin_not_authorized", msgParts); //$NON-NLS-1$
- throw ExceptionUtil.convertException(method, new AuthorizationException(errMsg));
- }
- try {
- return method.invoke(service, args);
- } catch (InvocationTargetException e) {
- throw e.getTargetException();
- }
- }
-
- /**
- * Builds an audit msg using given values including method signature string from given invocation using method
- * name and argument values.
- * @param securityContext
- * @param adminToken
- * @param requiredRoleName
- * @param invocation
- * @return
- * @since 5.0
- */
- private Object[] buildAuditMessage(SessionToken adminToken, String requiredRoleName, Method invocation) {
- return new Object[] {adminToken.getUsername(), adminToken.getSessionID().toString(), requiredRoleName, invocation.getName()};
- }
-
-}
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ClientInstance.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ClientInstance.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ClientInstance.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.io.Serializable;
-
-import org.teiid.dqp.internal.process.DQPWorkContext;
-
-import com.metamatrix.common.comm.api.Message;
-import com.metamatrix.common.comm.exception.CommunicationException;
-import com.metamatrix.common.util.crypto.Cryptor;
-
-/**
- * Represents a ClientConnection from the server's point of view. This interface
- * can be used by a ServerListener implementation to manage the incoming
- * client connections, retrieve information about a particular connection,
- * and send a message to a particular connection in the asynchronous message scenario.
- */
-public interface ClientInstance {
-
- /**
- * Send a message to this particular client using the asynch message key.
- * @param message The message to send
- * @param messageKey The key sent with the asynch query
- * @throws CommunicationException If an error occurs during the send
- */
- void send(Message message, Serializable messageKey);
-
- /**
- * Shutdown the server's connection to the client.
- * @throws CommunicationException If an error occurs during the shutdown
- */
- void shutdown() throws CommunicationException;
-
- Cryptor getCryptor();
-
- DQPWorkContext getWorkContext();
-}
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/LogonImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/LogonImpl.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/LogonImpl.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,192 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.CredentialMap;
-import org.teiid.dqp.internal.process.DQPWorkContext;
-
-import com.metamatrix.admin.api.exception.security.InvalidSessionException;
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.security.LogonException;
-import com.metamatrix.api.exception.security.MetaMatrixAuthenticationException;
-import com.metamatrix.api.exception.security.SessionServiceException;
-import com.metamatrix.common.api.MMURL;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.util.LogConstants;
-import com.metamatrix.dqp.client.ResultsFuture;
-import com.metamatrix.jdbc.api.ConnectionProperties;
-import com.metamatrix.platform.security.api.Credentials;
-import com.metamatrix.platform.security.api.ILogon;
-import com.metamatrix.platform.security.api.LogonResult;
-import com.metamatrix.platform.security.api.MetaMatrixSessionID;
-import com.metamatrix.platform.security.api.MetaMatrixSessionInfo;
-import com.metamatrix.platform.security.api.SessionToken;
-import com.metamatrix.platform.security.api.service.SessionServiceInterface;
-import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.service.api.exception.ServiceStateException;
-import com.metamatrix.platform.util.ProductInfoConstants;
-import com.metamatrix.server.ServerPlugin;
-
-public class LogonImpl implements ILogon {
-
- private SessionServiceInterface service;
- private String clusterName;
-
- public LogonImpl(SessionServiceInterface service, String clusterName) {
- this.service = service;
- this.clusterName = clusterName;
- }
-
- public LogonResult logon(Properties connProps) throws LogonException,
- ComponentNotFoundException {
-
- String applicationName = connProps.getProperty(MMURL.CONNECTION.APP_NAME);
- // user may be null if using trustedToken to log on
- String user = connProps.getProperty(MMURL.CONNECTION.USER_NAME);
- // password may be null if using trustedToken to log on
- String password = connProps.getProperty(MMURL.CONNECTION.PASSWORD);
- Credentials credential = null;
- if (password != null) {
- credential = new Credentials(password.toCharArray());
- }
-
- if(connProps.containsKey(ConnectionProperties.PROP_CREDENTIALS)) {
- handleCredentials(connProps, user, password);
- }
-
- Object payload = connProps.get(MMURL.CONNECTION.CLIENT_TOKEN_PROP);
-
- try {
- MetaMatrixSessionInfo sessionInfo = service.createSession(user,
- credential, (Serializable) payload, applicationName,
- connProps);
- // logon
- MetaMatrixSessionID sessionID = updateDQPContext(sessionInfo);
- LogManager.logDetail(LogConstants.CTX_SESSION, new Object[] {
- "Logon successful for \"", user, "\" - created SessionID \"", "" + sessionID, "\"" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- return new LogonResult(sessionInfo.getSessionToken(), sessionInfo.getProductInfo(), clusterName);
- } catch (MetaMatrixAuthenticationException e) {
- throw new LogonException(e, e.getMessage());
- } catch (ServiceException e) {
- throw new ComponentNotFoundException(e, e.getMessage());
- } catch (SessionServiceException e) {
- throw new LogonException(e, e.getMessage());
- }
- }
-
- private void handleCredentials(Properties connProps, String user,
- String password) throws LogonException {
- // Check if both credentials AND session token are used - if so, this is an error
- if(connProps.containsKey(ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD)) {
- throw new LogonException(ServerPlugin.Util.getString("LogonImpl.Invalid_use_of_credentials_and_token")); //$NON-NLS-1$
- }
-
- // Parse credentials and store CredentialMap as session token
- try {
- String credentials = connProps.getProperty(ConnectionProperties.PROP_CREDENTIALS);
- CredentialMap credentialMap = null;
- boolean defaultToLogon = false;
- if(credentials.startsWith(ConnectionProperties.DEFAULT_TO_LOGON)) {
- defaultToLogon = true;
- }
- int parenIndex = credentials.indexOf("("); //$NON-NLS-1$
- if(parenIndex >= 0) {
- credentialMap = CredentialMap.parseCredentials(credentials.substring(parenIndex));
- } else {
- credentialMap = new CredentialMap();
- }
- if(defaultToLogon) {
- credentialMap.setDefaultCredentialMode(CredentialMap.MODE_USE_DEFAULTS_GLOBALLY);
- Map<String, String> defaultCredentials = new HashMap<String, String>();
- defaultCredentials.put(CredentialMap.USER_KEYWORD, user);
- defaultCredentials.put(CredentialMap.PASSWORD_KEYWORD, password);
- credentialMap.setDefaultCredentials(defaultCredentials);
- } else {
- credentialMap.setDefaultCredentialMode(CredentialMap.MODE_IGNORE_DEFAULTS);
- }
- connProps.put(ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD, credentialMap);
- } catch(ConnectorException e) {
- throw new LogonException(e.getMessage());
- }
-
- // Remove credentials from info properties
- connProps.remove(ConnectionProperties.PROP_CREDENTIALS);
- }
-
- private MetaMatrixSessionID updateDQPContext(MetaMatrixSessionInfo sessionInfo) {
- MetaMatrixSessionID sessionID = sessionInfo.getSessionID();
- DQPWorkContext workContext = DQPWorkContext.getWorkContext();
- workContext.setSessionToken(sessionInfo.getSessionToken());
- workContext.setAppName(sessionInfo.getApplicationName());
- workContext.setTrustedPayload(sessionInfo.getTrustedToken());
- workContext.setVdbName(sessionInfo.getProductInfo(ProductInfoConstants.VIRTUAL_DB));
- workContext.setVdbVersion(sessionInfo.getProductInfo(ProductInfoConstants.VDB_VERSION));
- return sessionID;
- }
-
- public ResultsFuture<?> logoff() throws InvalidSessionException, MetaMatrixComponentException {
- try {
- this.service.closeSession(DQPWorkContext.getWorkContext().getSessionId());
- } catch (SessionServiceException e) {
- throw new MetaMatrixComponentException(e);
- } catch (ServiceException e) {
- throw new MetaMatrixComponentException(e);
- }
- return null;
- }
-
- public ResultsFuture<?> ping() throws InvalidSessionException,
- MetaMatrixComponentException {
- try {
- this.service.pingServer(DQPWorkContext.getWorkContext().getSessionId());
- } catch (ServiceStateException e) {
- throw new MetaMatrixComponentException(e);
- }
- return null;
- }
-
- @Override
- public void assertIdentity(SessionToken sessionId)
- throws InvalidSessionException, MetaMatrixComponentException {
- MetaMatrixSessionInfo sessionInfo;
- try {
- sessionInfo = this.service.validateSession(sessionId.getSessionID());
- } catch (SessionServiceException e) {
- throw new MetaMatrixComponentException(e);
- } catch (ServiceException e) {
- throw new MetaMatrixComponentException(e);
- }
- if (!sessionInfo.getSessionToken().equals(sessionInfo.getSessionToken())) {
- throw new InvalidSessionException();
- }
- this.updateDQPContext(sessionInfo);
- }
-
-}
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/ServerWorkItem.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,180 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-/**
- *
- */
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.concurrent.ExecutionException;
-
-import javax.crypto.SealedObject;
-
-import org.teiid.dqp.internal.process.DQPWorkContext;
-
-import com.metamatrix.admin.api.exception.AdminProcessingException;
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.api.exception.ExceptionHolder;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.comm.ClientServiceRegistry;
-import com.metamatrix.common.comm.api.Message;
-import com.metamatrix.common.comm.platform.socket.client.ServiceInvocationStruct;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ReflectionHelper;
-import com.metamatrix.dqp.client.ResultsFuture;
-import com.metamatrix.platform.PlatformPlugin;
-import com.metamatrix.platform.security.api.ILogon;
-import com.metamatrix.platform.security.api.service.SessionServiceInterface;
-import com.metamatrix.server.util.LogConstants;
-
-public class ServerWorkItem implements Runnable {
- private final ClientInstance socketClientInstance;
- private final Serializable messageKey;
- private final Message message;
- private final ClientServiceRegistry server;
- private final SessionServiceInterface sessionService;
-
- public ServerWorkItem(ClientInstance socketClientInstance,
- Serializable messageKey, Message message,
- ClientServiceRegistry server, SessionServiceInterface sessionService) {
- this.socketClientInstance = socketClientInstance;
- this.messageKey = messageKey;
- this.message = message;
- this.server = server;
- this.sessionService = sessionService;
- }
-
- /**
- * main entry point for remote method calls. encryption/decryption is
- * handled here so that it won't be done by the io thread
- */
- public void run() {
- DQPWorkContext.setWorkContext(this.socketClientInstance.getWorkContext());
- Message result = null;
- String service = null;
- final boolean encrypt = message.getContents() instanceof SealedObject;
- try {
- message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
-
- if (!(message.getContents() instanceof ServiceInvocationStruct)) {
- throw new AssertionError("unknown message contents"); //$NON-NLS-1$
- }
- final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)message.getContents();
- Object instance = server.getClientService(serviceStruct.targetClass);
- if (instance == null) {
- throw new ComponentNotFoundException(PlatformPlugin.Util.getString("ServerWorkItem.Component_Not_Found", serviceStruct.targetClass)); //$NON-NLS-1$
- }
- if (!(instance instanceof ILogon)) {
- DQPWorkContext workContext = this.socketClientInstance.getWorkContext();
- sessionService.validateSession(workContext.getSessionId());
- }
- service = serviceStruct.targetClass;
- ReflectionHelper helper = new ReflectionHelper(instance.getClass());
- Method m = helper.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
- Object methodResult;
- try {
- methodResult = m.invoke(instance, serviceStruct.args);
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
- ResultsFuture<Serializable> future = (ResultsFuture<Serializable>) methodResult;
- future.addCompletionListener(new ResultsFuture.CompletionListener<Serializable>() {
-
- public void onCompletion(
- ResultsFuture<Serializable> completedFuture) {
- Message asynchResult = new Message();
- try {
- asynchResult.setContents(completedFuture.get());
- } catch (InterruptedException e) {
- asynchResult.setContents(processException(e, serviceStruct.targetClass));
- } catch (ExecutionException e) {
- asynchResult.setContents(processException(e.getCause(), serviceStruct.targetClass));
- }
- sendResult(asynchResult, encrypt);
- }
-
- });
- } else { // synch call
- Message resultHolder = new Message();
- resultHolder.setContents((Serializable)methodResult);
- result = resultHolder;
- }
- } catch (Throwable t) {
- Message holder = new Message();
- holder.setContents(processException(t, service));
- result = holder;
- }
- if (result != null) {
- sendResult(result, encrypt);
- }
- }
-
- void sendResult(Message result, boolean encrypt) {
- if (encrypt) {
- try {
- result.setContents(socketClientInstance.getCryptor().sealObject(result.getContents()));
- } catch (CryptoException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
- socketClientInstance.send(result, messageKey);
- }
-
- private Serializable processException(Throwable e, String service) {
- String context = null;
- if (service != null) {
- context = this.server.getLoggingContextForService(service);
- }
- if (context == null) {
- context = LogConstants.CTX_ROUTER;
- }
- // Case 5558: Differentiate between system level errors and
- // processing errors. Only log system level errors as errors,
- // log the processing errors as warnings only
- if (e instanceof MetaMatrixProcessingException) {
- logProcessingException(e, context);
- } else if (e instanceof AdminProcessingException) {
- logProcessingException(e, context);
- } else {
- LogManager.logError(context, e, PlatformPlugin.Util.getString("ServerWorkItem.Received_exception_processing_request", this.socketClientInstance.getWorkContext().getConnectionID())); //$NON-NLS-1$
- }
-
- return new ExceptionHolder(e);
- }
-
- private void logProcessingException(Throwable e, String context) {
- Throwable cause = e;
- while (cause.getCause() != null && cause != cause.getCause()) {
- cause = cause.getCause();
- }
- StackTraceElement elem = cause.getStackTrace()[0];
- LogManager.logDetail(context, e, "Processing exception for session", this.socketClientInstance.getWorkContext().getConnectionID()); //$NON-NLS-1$
- LogManager.logWarning(context, PlatformPlugin.Util.getString("ServerWorkItem.processing_error", e.getMessage(), this.socketClientInstance.getWorkContext().getConnectionID(), e.getClass().getName(), elem)); //$NON-NLS-1$
- }
-
-}
\ No newline at end of file
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketClientInstance.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketClientInstance.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketClientInstance.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.io.Serializable;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-
-import org.teiid.dqp.internal.process.DQPWorkContext;
-
-import com.metamatrix.common.comm.ClientServiceRegistry;
-import com.metamatrix.common.comm.api.Message;
-import com.metamatrix.common.comm.exception.CommunicationException;
-import com.metamatrix.common.comm.platform.CommPlatformPlugin;
-import com.metamatrix.common.comm.platform.socket.ChannelListener;
-import com.metamatrix.common.comm.platform.socket.Handshake;
-import com.metamatrix.common.comm.platform.socket.ObjectChannel;
-import com.metamatrix.common.comm.platform.socket.SocketVMController;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.queue.WorkerPool;
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.common.util.crypto.Cryptor;
-import com.metamatrix.common.util.crypto.DhKeyGenerator;
-import com.metamatrix.common.util.crypto.NullCryptor;
-import com.metamatrix.core.log.MessageLevel;
-import com.metamatrix.platform.security.api.service.SessionServiceInterface;
-
-/**
- * Sockets implementation of the communication framework class representing the server's view of a client connection.
- * Implements the server-side of the sockets messaging protocol.
- * The client side of the protocol is implemented in SocketServerInstance.
- * Users of this class are expected to provide a WorkerPool for processing incoming messages. Users must also call read().
- * Users also provide a ServerListener implementation. The ServerListener is the application level object
- * processing the application level messages.
- */
-public class SocketClientInstance implements ChannelListener, ClientInstance {
-
- private final ObjectChannel objectSocket;
- private final WorkerPool workerPool;
- private final ClientServiceRegistry server;
- private Cryptor cryptor;
- private boolean usingEncryption;
- private DhKeyGenerator keyGen;
- private DQPWorkContext workContext = new DQPWorkContext();
- private SessionServiceInterface sessionService;
-
- public SocketClientInstance(ObjectChannel objectSocket, WorkerPool workerPool, ClientServiceRegistry server, boolean isClientEncryptionEnabled, SessionServiceInterface sessionService) {
- this.objectSocket = objectSocket;
- this.workerPool = workerPool;
- this.server = server;
- this.usingEncryption = isClientEncryptionEnabled;
- this.sessionService = sessionService;
- SocketAddress address = this.objectSocket.getRemoteAddress();
- if (address instanceof InetSocketAddress) {
- InetSocketAddress addr = (InetSocketAddress)address;
- this.workContext.setClientAddress(addr.getAddress().getHostAddress());
- this.workContext.setClientHostname(addr.getHostName());
- }
- }
-
- public void send(Message message, Serializable messageKey) {
- if (LogManager.isMessageToBeRecorded(SocketVMController.SOCKET_CONTEXT, MessageLevel.DETAIL)) {
- LogManager.logDetail(SocketVMController.SOCKET_CONTEXT, " message: " + message + " for request ID:" + messageKey); //$NON-NLS-1$ //$NON-NLS-2$
- }
- message.setMessageKey(messageKey);
- objectSocket.write(message);
- }
-
- /**
- * @return Returns the cryptor.
- */
- public Cryptor getCryptor() {
- return this.cryptor;
- }
-
- public void exceptionOccurred(Throwable t) {
- LogManager.logDetail(SocketVMController.SOCKET_CONTEXT, t, "Unhandled exception, closing client instance"); //$NON-NLS-1$
- }
-
- public void onConnection() throws CommunicationException {
- Handshake handshake = new Handshake();
- handshake.setVersion(SocketListener.getVersionInfo());
-
- if (usingEncryption) {
- keyGen = new DhKeyGenerator();
- byte[] publicKey;
- try {
- publicKey = keyGen.createPublicKey();
- } catch (CryptoException e) {
- throw new CommunicationException(e);
- }
- handshake.setPublicKey(publicKey);
- }
- this.objectSocket.write(handshake);
- }
-
- private void receivedHahdshake(Handshake handshake) throws CommunicationException {
- if (usingEncryption) {
- byte[] returnedPublicKey = handshake.getPublicKey();
-
- //ensure the key information
- if (returnedPublicKey == null) {
- throw new CommunicationException(CommPlatformPlugin.Util.getString("SocketClientInstance.invalid_sessionkey")); //$NON-NLS-1$
- }
-
- try {
- this.cryptor = keyGen.getSymmetricCryptor(returnedPublicKey);
- } catch (CryptoException e) {
- throw new CommunicationException(e);
- }
- this.keyGen = null;
- } else {
- this.cryptor = new NullCryptor();
- }
- }
-
- public void receivedMessage(Object msg) throws CommunicationException {
- if (msg instanceof Message) {
- processMessagePacket((Message)msg);
- } else if (msg instanceof Handshake) {
- receivedHahdshake((Handshake)msg);
- }
- }
-
- private void processMessagePacket(Message packet) {
- if (LogManager.isMessageToBeRecorded(SocketVMController.SOCKET_CONTEXT, MessageLevel.DETAIL)) {
- LogManager.logDetail(SocketVMController.SOCKET_CONTEXT, "processing message:" + packet); //$NON-NLS-1$
- }
- workerPool.execute(new ServerWorkItem(this, packet.getMessageKey(), packet, this.server, this.sessionService));
- }
-
- public void shutdown() throws CommunicationException {
- this.objectSocket.close();
- }
-
- public DQPWorkContext getWorkContext() {
- return this.workContext;
- }
-}
Deleted: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketListener.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketListener.java 2009-06-26 22:01:00 UTC (rev 1087)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/server/SocketListener.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -1,136 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.comm.platform.socket.server;
-
-import java.net.InetSocketAddress;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.net.ssl.SSLEngine;
-
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
-
-import com.metamatrix.common.comm.ClientServiceRegistry;
-import com.metamatrix.common.comm.platform.socket.ChannelListener;
-import com.metamatrix.common.comm.platform.socket.ObjectChannel;
-import com.metamatrix.common.comm.platform.socket.SSLAwareChannelHandler;
-import com.metamatrix.common.comm.platform.socket.SocketVMController;
-import com.metamatrix.common.comm.platform.socket.ChannelListener.ChannelListenerFactory;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.queue.WorkerPool;
-import com.metamatrix.common.queue.WorkerPoolFactory;
-import com.metamatrix.common.queue.WorkerPoolStats;
-import com.metamatrix.common.util.ApplicationInfo;
-import com.metamatrix.core.log.MessageLevel;
-import com.metamatrix.platform.security.api.service.SessionServiceInterface;
-import com.metamatrix.platform.vm.controller.SocketListenerStats;
-
-/**
- * Server-side class to listen for new connection requests and create a SocketClientConnection for each connection request.
- */
-public class SocketListener implements ChannelListenerFactory {
- private ClientServiceRegistry server;
- private SSLAwareChannelHandler channelHandler;
- private Channel serverChanel;
- private boolean isClientEncryptionEnabled;
- private SessionServiceInterface sessionService;
- private WorkerPool workerPool;
- private ExecutorService nettyPool;
-
- /**
- *
- * @param port
- * @param bindaddress
- * @param server
- * @param inputBufferSize
- * @param outputBufferSize
- * @param workerPool
- * @param engine null if SSL is disabled
- */
- public SocketListener(int port, String bindAddress,
- ClientServiceRegistry server, int inputBufferSize,
- int outputBufferSize, int maxWorkers, SSLEngine engine, boolean isClientEncryptionEnabled, SessionServiceInterface sessionService) {
- this.isClientEncryptionEnabled = isClientEncryptionEnabled;
- this.sessionService = sessionService;
- if (port < 0 || port > 0xFFFF) {
- throw new IllegalArgumentException("port out of range:" + port); //$NON-NLS-1$
- }
-
- this.server = server;
- this.workerPool = WorkerPoolFactory.newWorkerPool("SocketWorker", maxWorkers); //$NON-NLS-1$
- this.nettyPool = Executors.newCachedThreadPool();
- if (LogManager.isMessageToBeRecorded(SocketVMController.SOCKET_CONTEXT, MessageLevel.DETAIL)) {
- LogManager.logDetail(SocketVMController.SOCKET_CONTEXT, "server = " + this.server + "binding to port:" + port); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- ChannelFactory factory = new NioServerSocketChannelFactory(nettyPool, nettyPool, Math.min(Runtime.getRuntime().availableProcessors(), maxWorkers));
-
- ServerBootstrap bootstrap = new ServerBootstrap(factory);
- this.channelHandler = new SSLAwareChannelHandler(this, engine, Thread.currentThread().getContextClassLoader());
- bootstrap.setPipelineFactory(channelHandler);
- if (inputBufferSize != 0) {
- bootstrap.setOption("receiveBufferSize", new Integer(inputBufferSize)); //$NON-NLS-1$
- }
- if (outputBufferSize != 0) {
- bootstrap.setOption("sendBufferSize", new Integer(outputBufferSize)); //$NON-NLS-1$
- }
- bootstrap.setOption("keepAlive", Boolean.TRUE); //$NON-NLS-1$
-
- this.serverChanel = bootstrap.bind(new InetSocketAddress(bindAddress, port));
- }
-
- public WorkerPoolStats getProcessPoolStats() {
- return this.workerPool.getStats();
- }
-
- public int getPort() {
- return ((InetSocketAddress)this.serverChanel.getLocalAddress()).getPort();
- }
-
- static String getVersionInfo() {
- return ApplicationInfo.getInstance().getMajorReleaseNumber();
- }
-
- public void stop() {
- this.serverChanel.close();
- this.workerPool.shutdownNow();
- this.nettyPool.shutdownNow();
- }
-
- public SocketListenerStats getStats() {
- SocketListenerStats stats = new SocketListenerStats();
- stats.objectsRead = this.channelHandler.getObjectsRead();
- stats.objectsWritten = this.channelHandler.getObjectsWritten();
- stats.sockets = this.channelHandler.getConnectedChannels();
- stats.maxSockets = this.channelHandler.getMaxConnectedChannels();
- return stats;
- }
-
- public ChannelListener createChannelListener(ObjectChannel channel) {
- return new SocketClientInstance(channel, this.workerPool, this.server, this.isClientEncryptionEnabled, this.sessionService);
- }
-
-}
\ No newline at end of file
Copied: trunk/server/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java (from rev 1067, trunk/common-internal/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/common/config/CurrentConfiguration.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,396 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.config;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.Properties;
+
+import com.metamatrix.common.CommonPlugin;
+import com.metamatrix.common.config.api.ComponentType;
+import com.metamatrix.common.config.api.ComponentTypeID;
+import com.metamatrix.common.config.api.Configuration;
+import com.metamatrix.common.config.api.ConfigurationID;
+import com.metamatrix.common.config.api.ConfigurationModelContainer;
+import com.metamatrix.common.config.api.Host;
+import com.metamatrix.common.config.api.HostID;
+import com.metamatrix.common.config.api.ResourceModel;
+import com.metamatrix.common.config.api.SharedResource;
+import com.metamatrix.common.config.api.VMComponentDefn;
+import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.common.config.model.BasicHost;
+import com.metamatrix.common.config.reader.CurrentConfigurationReader;
+import com.metamatrix.common.config.reader.PropertiesConfigurationReader;
+import com.metamatrix.common.properties.UnmodifiableProperties;
+import com.metamatrix.common.util.ApplicationInfo;
+import com.metamatrix.common.util.ErrorMessageKeys;
+import com.metamatrix.common.util.NetUtils;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.ReflectionHelper;
+
+/**
+ * <p>
+ * This class represents a single and universal framework for accessing
+ * the current configuration for an application or server VM. The current
+ * configuration contains the specification of runtime properties and
+ * component deployment information. Depending upon the bootstrap information,
+ * this framework may access the configuration information from a central
+ * repository or simply from a local file.
+ * </p>
+ * <p>
+ * This framework can be configured to periodically refresh the cached
+ * configuation information, and a separate thread is used to do this in
+ * the background. As such, the static <code>shutdown()</code> method
+ * should be called by applications when exiting. This method will block until
+ * this framework has successfully shutdown and cleaned up all resources,
+ * and will return gracefully if the method were already called.
+ * Note, however, that any call to this framework to obtain configuration
+ * information will restart the framework, requiring another eventual
+ * shutdown.
+ * </p>
+ */
+public final class CurrentConfiguration {
+ /*
+ * This property enables the overriding of the default {@link BOOTSTRAP_FILE_NAME}
+ */
+ public static final String BOOTSTRAP_FILE_PROPERTY_OVERRIDE = "teiid.bootstrap.file"; //$NON-NLS-1$
+
+ public static final String BOOTSTRAP_FILE_NAME = "teiid.properties"; //$NON-NLS-1$
+ public static final String CONFIGURATION_READER_CLASS_PROPERTY_NAME = "metamatrix.config.reader"; //$NON-NLS-1$
+ public static final String CLUSTER_NAME = "cluster.name"; //$NON-NLS-1$
+ public static final String CONFIGURATION_NAME= "configuration.name"; //$NON-NLS-1$
+ public static final String CLUSTER_MEMBERS = "cluster.unicast.members"; //$NON-NLS-1$
+
+ private CurrentConfigurationReader reader;
+ private Properties bootstrapProperties;
+ private Properties modifyableBootstrapProperties;
+ private Properties systemBootstrapProperties;
+ private String bindAddress;
+ private InetAddress hostAddress;
+ private String configurationName;
+ private String processName;
+
+ private static CurrentConfiguration INSTANCE = new CurrentConfiguration();
+
+ public static CurrentConfiguration getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Private constructor that prevents instantiation.
+ */
+ private CurrentConfiguration() {
+ setHostProperties(null);
+ }
+
+ private void setHostProperties(String bind) {
+ Host host = getDefaultHost();
+ this.configurationName = host.getFullName();
+ String hostName = host.getHostAddress();
+ if (bind == null) {
+ bind = host.getBindAddress();
+ }
+
+ boolean bindAddressDefined = (bind != null && bind.length() > 0);
+ boolean hostNameDefined = (hostName != null && hostName.length() > 0);
+
+ try {
+ if (hostNameDefined) {
+ this.hostAddress = NetUtils.resolveHostByName(hostName);
+ }
+
+ if (bindAddressDefined) {
+ this.bindAddress = bind;
+
+ if (!hostNameDefined) {
+ this.hostAddress = InetAddress.getByName(bindAddress);
+ }
+ }
+ else {
+ if (!hostNameDefined) {
+ this.hostAddress = NetUtils.getInstance().getInetAddress();
+ }
+ this.bindAddress = this.hostAddress.getHostAddress();
+ }
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+
+ // these properties will be used to identify the server in TCP based cluster setup.
+ String unicastMembers = bootstrapProperties.getProperty(CLUSTER_MEMBERS);
+ if (unicastMembers == null) {
+ unicastMembers = this.configurationName+"|"+this.hostAddress.getCanonicalHostName(); //$NON-NLS-1$
+ }
+ else {
+ unicastMembers = unicastMembers+","+this.configurationName+"|"+this.hostAddress.getCanonicalHostName(); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ modifyableBootstrapProperties.setProperty(CLUSTER_MEMBERS, unicastMembers);
+ }
+
+ public boolean isAvailable() {
+ return this.reader != null;
+ }
+
+ /**
+ * Return the stringified representation of this application information object.
+ * @return the string form of this object; never null
+ */
+ public String getHostInfo() {
+ StringBuffer sb = new StringBuffer("Host Information"); //$NON-NLS-1$
+ sb.append('\n');
+ sb.append(" VM Name: " + processName ); //$NON-NLS-1$
+ sb.append('\n');
+ sb.append(" Hostname: " + hostAddress.getCanonicalHostName() ); //$NON-NLS-1$
+ sb.append('\n');
+ sb.append(" Version: ").append(ApplicationInfo.getInstance().getReleaseNumber()); //$NON-NLS-1$
+ sb.append('\n');
+ sb.append(" Build Date: ").append(ApplicationInfo.getInstance().getBuildDate()); //$NON-NLS-1$
+ return sb.toString();
+ }
+
+ public void setProcessName(String name) {
+ VMComponentDefn deployedVM;
+ try {
+ deployedVM = getConfiguration().getVMForHost(getDefaultHost().getName(), name);
+ } catch (ConfigurationException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+
+ if (deployedVM == null) {
+ throw new MetaMatrixRuntimeException(CommonPlugin.Util.getString("CurrentConfiguration.unknown_process", name)); //$NON-NLS-1$
+ }
+ this.processName = name;
+ setHostProperties(deployedVM.getBindAddress());
+ }
+
+ public String getBindAddress() {
+ return bindAddress;
+ }
+
+ public InetAddress getHostAddress() {
+ return hostAddress;
+ }
+
+ public String getConfigurationName() {
+ return configurationName;
+ }
+
+ public String getProcessName() {
+ return processName;
+ }
+
+ public String getClusterName() throws ConfigurationException {
+ Properties props = getResourceProperties(ResourceNames.JGROUPS);
+ return props.getProperty(CLUSTER_NAME, "Teiid-Cluster"); //$NON-NLS-1$
+ }
+
+ /**
+ * Get all of the configuration properties. The properties
+ * that are returned have default properties that are the bootstrap properties.
+ * @return the immutable properties; never null
+ * @throws ConfigurationException if the current configuration and/or
+ * bootstrap properties could not be obtained
+ */
+ public Properties getProperties() {
+ try {
+ ConfigurationModelContainer cmc = getReader().getConfigurationModel();
+ ComponentTypeID id = cmc.getConfiguration().getComponentTypeID();
+ Properties result = new Properties(getBootStrapProperties());
+ PropertiesUtils.putAll(result, cmc.getDefaultPropertyValues(id));
+ PropertiesUtils.putAll(result, cmc.getConfiguration().getProperties());
+ return new UnmodifiableProperties(result);
+ } catch (ConfigurationException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+
+ /**
+ * Get the connection properties for the specified resource. The resourse name
+ * is dependent on the type of resource. For services, excluding connectors,
+ * the resource name will be the component type name {@link com.metamatrix.common.config.api.ComponentType}.
+ * For other types, they will generally have a predefined static variable
+ * called RESOURCE_NAME that will be used to ask for its properties.
+ * @param resourceName is the name of the resource to obtain properties for.
+ * @return the immutable properties; never null
+ * @throws ConfigurationException if the current configuration and/or
+ * bootstrap properties could not be obtained
+ */
+ public Properties getResourceProperties(String resourceName) throws ConfigurationException {
+ Properties result;
+
+ SharedResource sr = getReader().getConfigurationModel().getResource(resourceName);
+
+ Properties props;
+ if (sr != null) {
+ props = ResourceModel.getDefaultProperties(resourceName);
+ props.putAll(sr.getProperties());
+ } else {
+ props = new Properties();
+
+ }
+
+ // allow the system properties to override
+ PropertiesUtils.setOverrideProperies(props, getSystemBootStrapProperties());
+
+ result = new UnmodifiableProperties(props);
+
+ return result;
+ }
+
+ /**
+ * Get the current configuration that is to be used for deployment.
+ * @return the Configuration used for deployment
+ * @throws ConfigurationException if the current configuration could not be obtained
+ */
+ public Configuration getConfiguration() throws ConfigurationException {
+ Configuration config = getReader().getConfigurationModel().getConfiguration();
+ if ( config == null ) {
+ throw new ConfigurationException(ErrorMessageKeys.CONFIG_ERR_0021, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0021));
+ }
+ return config;
+ }
+
+
+ /**
+ * Get the current configuration that is to be used for deployment.
+ * @return the Configuration used for deployment
+ * @throws ConfigurationException if the current configuration could not be obtained
+ */
+ public ConfigurationModelContainer getConfigurationModel() throws ConfigurationException {
+ ConfigurationModelContainer config = null;
+ try {
+ config = getReader().getConfigurationModel();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ if (config == null) {
+ throw new ConfigurationException(ErrorMessageKeys.CONFIG_ERR_0022,
+ CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0022));
+ }
+
+ return config;
+ }
+
+ /**
+ * Returns a <code>Collection</code> of type <code>ComponentType</code> that represent
+ * all the ComponentTypes defined.
+ * @param includeDeprecated true if class names that have been deprecated should be
+ * included in the returned list, or false if only non-deprecated constants should be returned.
+ * @return List of type <code>ComponentType</code>
+ * @throws ConfigurationException if an error occurred within or during communication with the Configuration Service.
+ * @see com.metamatrix.common.api.ComponentType
+ */
+ public Collection<ComponentType> getComponentTypes(boolean includeDeprecated) throws ConfigurationException {
+ return getReader().getConfigurationModel().getComponentTypes().values();
+ }
+
+
+ /**
+ * Returns the Host based on the current running machine.
+ * @return the full Host object
+ * @throws ConfigurationException if an error occurred within or during
+ * communication with the Configuration Service, or if there is no object
+ * for the given ID.
+ */
+ public Host getDefaultHost() {
+ String name = getBootStrapProperties().getProperty(CONFIGURATION_NAME, "embedded"); //$NON-NLS-1$
+ BasicHost host = new BasicHost(new ConfigurationID(name), new HostID(name), Host.HOST_COMPONENT_TYPE_ID);
+
+ Properties props = new Properties();
+ props.setProperty(com.metamatrix.admin.api.objects.Host.INSTALL_DIR, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.INSTALL_DIR, System.getProperty("user.dir"))); //$NON-NLS-1$
+ props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_DIRECTORY, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_DIRECTORY, System.getProperty("user.dir"))); //$NON-NLS-1$
+ props.setProperty(com.metamatrix.admin.api.objects.Host.LOG_DIRECTORY, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.LOG_DIRECTORY, System.getProperty("user.dir"))); //$NON-NLS-1$
+ props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_BIND_ADDRESS, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_BIND_ADDRESS, "")); //$NON-NLS-1$
+ props.setProperty(com.metamatrix.admin.api.objects.Host.HOST_PHYSICAL_ADDRESS, getBootStrapProperties().getProperty(com.metamatrix.admin.api.objects.Host.HOST_PHYSICAL_ADDRESS, "")); //$NON-NLS-1$
+
+ host.setProperties(props);
+ return host;
+ }
+
+
+ /**
+ * Reset causes not just a refresh, but the bootstrapping process
+ * to occur again.
+ */
+ public static void reset() {
+ INSTANCE = new CurrentConfiguration();
+ }
+
+ public synchronized Properties getBootStrapProperties() {
+ if (bootstrapProperties == null) {
+ Properties systemBootStrapProps = getSystemBootStrapProperties();
+ Properties bootstrapProps = new Properties(systemBootStrapProps);
+ InputStream bootstrapPropStream = null;
+
+ String bootstrapfile = systemBootStrapProps.getProperty(BOOTSTRAP_FILE_PROPERTY_OVERRIDE, BOOTSTRAP_FILE_NAME);
+ try {
+ bootstrapPropStream = this.getClass().getClassLoader().getResourceAsStream(bootstrapfile);
+ if (bootstrapPropStream != null) {
+ bootstrapProps.load(bootstrapPropStream);
+ }
+ } catch (IOException e) {
+ throw new MetaMatrixRuntimeException(ErrorMessageKeys.CONFIG_ERR_0069, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0069, BOOTSTRAP_FILE_NAME));
+ } finally {
+ try {
+ if (bootstrapPropStream != null) {
+ bootstrapPropStream.close();
+ }
+ } catch (IOException e ) {
+ }
+ }
+ modifyableBootstrapProperties = bootstrapProps;
+ bootstrapProperties = new UnmodifiableProperties(bootstrapProps);
+ }
+ return bootstrapProperties;
+ }
+
+ public synchronized final Properties getSystemBootStrapProperties() {
+ if (systemBootstrapProperties == null) {
+ systemBootstrapProperties = new UnmodifiableProperties(System.getProperties());
+ }
+ return systemBootstrapProperties;
+ }
+
+ synchronized CurrentConfigurationReader getReader() throws ConfigurationException {
+ if (reader == null) {
+ // Get the default bootstrap properties from the System properties ...
+ Properties bootstrap = getBootStrapProperties();
+
+ String readerClassName = bootstrap.getProperty( CONFIGURATION_READER_CLASS_PROPERTY_NAME, PropertiesConfigurationReader.class.getName() );
+
+ try {
+ reader = (CurrentConfigurationReader)ReflectionHelper.create(readerClassName, null, Thread.currentThread().getContextClassLoader());
+ } catch (Exception e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ return reader;
+ }
+}
Copied: trunk/server/src/main/java/com/metamatrix/common/config/ResourceNames.java (from rev 1067, trunk/common-internal/src/main/java/com/metamatrix/common/config/ResourceNames.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/config/ResourceNames.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/common/config/ResourceNames.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.config;
+
+/**
+* ResourceNames defines the different resources that require
+* connection properties. These properties are loaded up by
+* the {@link CurrentConfiguration} and made available by calling
+* the method {@link #getResourceProperties}. The following
+* are the basis for the names:
+* - CompTypes, excluding connectors (e.g., Config Service, Session Service, etc).
+* - internal operations (e.g., Runtime Metadata, logging, cursors, etc.)
+*/
+public interface ResourceNames {
+
+
+ public static final String RUNTIME_METADATA_SERVICE = "RuntimeMetadataService"; //$NON-NLS-1$
+ public static final String MEMBERSHIP_SERVICE = "MembershipService"; //$NON-NLS-1$
+ public static final String XA_TRANSACTION_MANAGER = "XATransactionManager"; //$NON-NLS-1$
+ public static final String INDEXING_SERVICE = "IndexingService"; //$NON-NLS-1$
+ public static final String JGROUPS = "JGroups"; //$NON-NLS-1$
+ public static final String SSL = "SSL"; //$NON-NLS-1$
+}
Copied: trunk/server/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java (from rev 1067, trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/common/config/model/ComponentCryptoUtil.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.config.model;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import com.metamatrix.common.config.CurrentConfiguration;
+import com.metamatrix.common.config.api.ComponentDefn;
+import com.metamatrix.common.config.api.ComponentType;
+import com.metamatrix.common.config.api.ComponentTypeDefn;
+import com.metamatrix.common.config.api.ConfigurationModelContainer;
+import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.common.object.PropertyDefinition;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.common.util.crypto.CryptoException;
+import com.metamatrix.common.util.crypto.CryptoUtil;
+import com.metamatrix.core.util.Assertion;
+
+
+/**
+ * Utilities for encrypting and decrypting properties of configuration ComponentDefns
+ * @since 4.3
+ */
+public class ComponentCryptoUtil {
+
+
+ /**
+ * Check whether the encrypted properties for the specified ComponentDefn can be decrypted.
+ * @param defn The ComponentDefn to check.
+ * @param componentTypeDefns Collection<ComponentTypeDefn> The ComponentTypeDefns containing the
+ * PropertyDefinitions for the specified ComponentDefn.
+ * @return true if the properties could be decrypted for that defn.
+ * @since 4.3
+ */
+ public static boolean checkPropertiesDecryptable(ComponentDefn defn, Collection componentTypeDefns) {
+ boolean result = true;
+
+ try {
+ decryptProperties(defn, componentTypeDefns);
+ } catch (CryptoException e) {
+ result = false;
+ }
+
+ return result;
+ }
+
+ /**
+ * Bails on the first masked property name that's contained in props but the value
+ * can't be decrypted. All masked properties that exist in props must be decryptable.
+ * @param props
+ * @param componentTypeIdentifier
+ * @return
+ * @since 4.3
+ */
+ public static boolean checkPropertiesDecryptable(Properties props,
+ Collection maskedPropertyNames) {
+ if (maskedPropertyNames != null) {
+ Iterator propItr = maskedPropertyNames.iterator();
+ while (propItr.hasNext()) {
+ String maskedPropName = (String)propItr.next();
+ String maskedValue = null;
+ if (props != null) {
+ maskedValue = props.getProperty(maskedPropName);
+ }
+ if (maskedValue != null && !CryptoUtil.canDecrypt(maskedValue)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public static Properties getDecryptedProperties(ComponentDefn defn) throws ConfigurationException, CryptoException {
+ ConfigurationModelContainer configModel = CurrentConfiguration.getInstance().getConfigurationModel();
+
+ ComponentType componentType = configModel.getComponentType(defn.getComponentTypeID().getName());
+ Assertion.isNotNull(componentType, "unknown component type"); //$NON-NLS-1$
+
+ Collection compTypeDefns = componentType.getComponentTypeDefinitions();
+ return decryptProperties(defn, compTypeDefns);
+ }
+
+ private static Properties decryptProperties(ComponentDefn defn,
+ Collection compTypeDefns) throws CryptoException {
+ Properties result = PropertiesUtils.clone(defn.getProperties(), false);
+ for ( Iterator compTypeDefnItr = compTypeDefns.iterator(); compTypeDefnItr.hasNext(); ) {
+ ComponentTypeDefn typeDefn = (ComponentTypeDefn) compTypeDefnItr.next();
+ PropertyDefinition propDefn = typeDefn.getPropertyDefinition();
+ String propName = propDefn.getName();
+ String propValue = result.getProperty(propName);
+ if ( propValue != null && propDefn.isMasked() ) {
+ propValue = CryptoUtil.getDecryptor().decrypt(propValue);
+ result.setProperty(propName, propValue);
+ }
+ }
+
+ return result;
+ }
+
+}
Copied: trunk/server/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java (from rev 1067, trunk/common-internal/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/common/config/model/PropertyValidations.java 2009-06-26 22:06:04 UTC (rev 1088)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.config.model;
+
+import java.util.Iterator;
+import java.util.List;
+
+import com.metamatrix.common.CommonPlugin;
+import com.metamatrix.common.config.CurrentConfiguration;
+import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.core.util.StringUtil;
+
+
+
+
+/**
+ * @since 4.3
+ */
+public class PropertyValidations {
+
+
+
+ public static final String UDP_MCAST_ADDR_PROPERTY = "udp.mcast_addr"; //$NON-NLS-1$
+ public static final String SYSTEM_NAME = CurrentConfiguration.CLUSTER_NAME;
+
+ private static final String MULTICAST_PORT_FORMAT = "224.255.255.255"; //$NON-NLS-1$
+
+
+ /**
+ * @see com.metamatrix.common.util.commandline.IPropertyValidation#isPropertyValid(java.lang.String, java.lang.String)
+ * @since 4.3
+ */
+ public void isPropertyValid(String key,
+ String value) throws ConfigurationException {
+
+ if (key == null) {
+ return;
+ }
+ if (key.equalsIgnoreCase(UDP_MCAST_ADDR_PROPERTY)) {
+ validate_multicast_port(key, value);
+ }
+
+ if (key.equalsIgnoreCase(SYSTEM_NAME)) {
+ validate_nonnull_and_contiguous("System Name", key, value);//$NON-NLS-1$
+ }
+ }
+
+ protected void validate_multicast_port(String key, String value) throws ConfigurationException {
+ if (value == null || value.trim().length() == 0) {
+ throwException(CommonPlugin.Util.getString("PropertyValidation.Inv