Author: shawkins
Date: 2012-06-28 16:02:25 -0400 (Thu, 28 Jun 2012)
New Revision: 4212
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java
trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TransportService.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java
trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java
trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
Log:
TEIID-2059 refining the wait logic with additional configuration options
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-06-28 19:58:01 UTC
(rev 4211)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-06-28 20:02:25 UTC
(rev 4212)
@@ -47,6 +47,7 @@
<li>VDB.getUrl has been removed.
<li>VDB.Status now has three states - LOADING, ACTIVE, REMOVED. To check for
validity use the isValid method, rather than checking for the VALID state.
<li>The standalone and cli configuration files specify a setting for the teiid
subsystem policy-decider-module. If a module is not specified, then data roles will not
be checked.
+ <li>local connections specifying a VDB version will wait for their VDB to finish
loading before allowing a connection.
<ul>
<h4>from 7.x</h4>
Modified: trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2012-06-28 19:58:01 UTC
(rev 4211)
+++ trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2012-06-28 20:02:25 UTC
(rev 4212)
@@ -33,14 +33,13 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.core.util.ReflectionHelper;
-import org.teiid.net.CommunicationException;
-import org.teiid.net.ConnectionException;
import org.teiid.net.ServerConnection;
public class EmbeddedProfile implements ConnectionProfile {
public static final String USE_CALLING_THREAD = "useCallingThread";
//$NON-NLS-1$
+ public static final String WAIT_FOR_LOAD = "waitForLoad"; //$NON-NLS-1$
/**
* This method tries to make a connection to the given URL. This class
@@ -56,10 +55,6 @@
return new ConnectionImpl(sc, info, url);
} catch (TeiidRuntimeException e) {
throw TeiidSQLException.create(e);
- } catch (ConnectionException e) {
- throw TeiidSQLException.create(e);
- } catch (CommunicationException e) {
- throw TeiidSQLException.create(e);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
}
@@ -67,14 +62,12 @@
protected ServerConnection createServerConnection(Properties info) throws TeiidException
{
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- try {
- final Module module =
Module.getCallerModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.teiid"));
//$NON-NLS-1$
- Thread.currentThread().setContextClassLoader(module.getClassLoader());
- return
(ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection",
Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, USE_CALLING_THREAD, true)),
Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
- } catch (ModuleLoadException e) {
- throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20008,
JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20008));
- }
+ try {
+ final Module module =
Module.getCallerModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.teiid"));
//$NON-NLS-1$
+ Thread.currentThread().setContextClassLoader(module.getClassLoader());
+ return
(ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection",
Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, USE_CALLING_THREAD, true)),
Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$
+ } catch (ModuleLoadException e) {
+ throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20008,
JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20008));
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
Modified: trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2012-06-28 19:58:01 UTC (rev
4211)
+++ trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2012-06-28 20:02:25 UTC (rev
4212)
@@ -71,6 +71,7 @@
BaseDataSource.VDB_VERSION,
BaseDataSource.USER_NAME,
BaseDataSource.PASSWORD,
+ EmbeddedProfile.WAIT_FOR_LOAD,
TeiidURL.CONNECTION.AUTO_FAILOVER,
TeiidURL.CONNECTION.DISCOVERY_STRATEGY,
TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION,
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2012-06-28 19:58:01 UTC
(rev 4211)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2012-06-28 20:02:25 UTC
(rev 4212)
@@ -138,7 +138,7 @@
@Test public void testGetPropertyInfo1() throws Exception {
DriverPropertyInfo info[] =
drv.getPropertyInfo("jdbc:teiid:vdb@mm://localhost:12345;applicationName=x",
null); //$NON-NLS-1$
- assertEquals(24, info.length);
+ assertEquals(25, info.length);
assertEquals(false, info[0].required);
assertEquals("ApplicationName", info[0].name); //$NON-NLS-1$
assertEquals("x", info[0].value); //$NON-NLS-1$
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TransportService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TransportService.java 2012-06-28
19:58:01 UTC (rev 4211)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TransportService.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -55,6 +55,7 @@
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
+import org.teiid.net.ConnectionException;
import org.teiid.net.socket.AuthenticationType;
import org.teiid.security.SecurityHelper;
import org.teiid.services.SessionServiceImpl;
@@ -104,13 +105,10 @@
}
@Override
- public void waitForFinished(String vdbName, int vdbVersion) {
+ public void waitForFinished(String vdbName, int vdbVersion,
+ int timeOutMillis) throws ConnectionException {
VDBRepository repo = this.vdbRepositoryInjector.getValue();
- try {
- repo.waitForFinished(vdbName, vdbVersion);
- } catch (InterruptedException e) {
- return; //just allow the thread to continue/error
- }
+ repo.waitForFinished(vdbName, vdbVersion, timeOutMillis);
}
@Override
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-28 19:58:01
UTC (rev 4211)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-28 20:02:25
UTC (rev 4212)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -32,6 +31,7 @@
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@@ -41,12 +41,14 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.CoreConstants;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataStore;
+import org.teiid.net.ConnectionException;
import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.TransformationMetadata.Resource;
@@ -60,10 +62,8 @@
* Repository for VDBs
*/
public class VDBRepository implements Serializable{
- private static final int DEPLOY_TIMEOUT = 60000;
- private static final int LOAD_TIMEOUT = 600000;
-
private static final long serialVersionUID = 312177538191772674L;
+ private static final int DEFAULT_TIMEOUT_MILLIS =
PropertiesUtils.getIntProperty(System.getProperties(),
"org.teiid.clientVdbLoadTimeoutMillis", 300000); //$NON-NLS-1$
private NavigableMap<VDBKey, CompositeVDB> vdbRepo = new
ConcurrentSkipListMap<VDBKey, CompositeVDB>();
private MetadataStore systemStore;
@@ -108,25 +108,43 @@
notifyAdd(vdb.getName(), vdb.getVersion(), cvdb);
}
- public void waitForFinished(String vdbName, int vdbVersion) throws InterruptedException
{
+ public void waitForFinished(String vdbName, int vdbVersion, int timeOutMillis) throws
ConnectionException {
CompositeVDB cvdb = null;
VDBKey key = new VDBKey(vdbName, vdbVersion);
- Date toWait = new Date(System.currentTimeMillis() + DEPLOY_TIMEOUT);
+ long timeOutNanos = 0;
+ if (timeOutMillis >= 0) {
+ timeOutNanos = TimeUnit.MILLISECONDS.toNanos(DEFAULT_TIMEOUT_MILLIS);
+ } else {
+ //TODO allow a configurable default
+ timeOutNanos = TimeUnit.MINUTES.toNanos(10);
+ }
lock.lock();
try {
- while (cvdb == null) {
- cvdb = this.vdbRepo.get(key);
- if (cvdb == null && !vdbAdded.awaitUntil(toWait)) {
- return; //TODO: should there be a message/exception
+ while ((cvdb = this.vdbRepo.get(key)) == null) {
+ if (timeOutNanos <= 0) {
+ throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40096,
timeOutMillis, vdbName, vdbVersion));
}
+ timeOutNanos = this.vdbAdded.awaitNanos(timeOutNanos);
+
}
+ } catch (InterruptedException e) {
+ return;
} finally {
lock.unlock();
}
VDBMetaData vdb = cvdb.getVDB();
+ long finishNanos = System.nanoTime() + timeOutNanos;
synchronized (vdb) {
- while (vdb.isLoading()) {
- vdb.wait(LOAD_TIMEOUT);
+ while (vdb.getStatus() != Status.ACTIVE) {
+ if (timeOutNanos <= 0) {
+ throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40097,
timeOutMillis, vdbName, vdbVersion, vdb.getValidityErrors()));
+ }
+ try {
+ vdb.wait(timeOutNanos);
+ } catch (InterruptedException e) {
+ return;
+ }
+ timeOutNanos = finishNanos - System.nanoTime();
}
}
}
Modified: trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-28 19:58:01
UTC (rev 4211)
+++ trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-28 20:02:25
UTC (rev 4212)
@@ -221,7 +221,14 @@
protected ObjectReplicator replicator;
protected BufferServiceImpl bufferService = new BufferServiceImpl();
protected TransactionDetectingTransactionServer transactionService = new
TransactionDetectingTransactionServer();
- protected ClientServiceRegistryImpl services = new ClientServiceRegistryImpl();
+ protected boolean waitForLoad;
+ protected ClientServiceRegistryImpl services = new ClientServiceRegistryImpl() {
+ public void waitForFinished(String vdbName, int vdbVersion, int timeOutMillis) throws
ConnectionException {
+ if (waitForLoad) {
+ repo.waitForFinished(vdbName, vdbVersion, timeOutMillis);
+ }
+ };
+ };
protected LogonImpl logon;
private TeiidDriver driver = new TeiidDriver();
protected ConnectorManagerRepository cmr = new
ProviderAwareConnectorManagerRepository();
Modified: trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java 2012-06-28 19:58:01
UTC (rev 4211)
+++ trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java 2012-06-28 20:02:25
UTC (rev 4212)
@@ -108,5 +108,7 @@
TEIID40093, //no sources
TEIID40094, //invalid metadata repso
TEIID40095, //deployment failed
+ TEIID40096, //vdb deploy timeout
+ TEIID40097, //vdb finish timeout
}
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java 2012-06-28
19:58:01 UTC (rev 4211)
+++ trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -23,6 +23,7 @@
package org.teiid.transport;
import org.teiid.core.ComponentNotFoundException;
+import org.teiid.net.ConnectionException;
import org.teiid.net.socket.AuthenticationType;
import org.teiid.security.SecurityHelper;
@@ -38,7 +39,7 @@
SecurityHelper getSecurityHelper();
AuthenticationType getAuthenticationType();
+
+ void waitForFinished(String vdbName, int vdbVersion, int timeOutMillis) throws
ConnectionException;
- void waitForFinished(String vdbName, int vdbVersion);
-
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java
===================================================================
---
trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java 2012-06-28
19:58:01 UTC (rev 4211)
+++
trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -26,6 +26,7 @@
import org.teiid.core.ComponentNotFoundException;
import org.teiid.core.util.ReflectionHelper;
+import org.teiid.net.ConnectionException;
import org.teiid.net.socket.AuthenticationType;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.security.SecurityHelper;
@@ -105,7 +106,8 @@
}
@Override
- public void waitForFinished(String vdbName, int vdbVersion) {
+ public void waitForFinished(String vdbName, int vdbVersion,
+ int timeOutMillis) throws ConnectionException {
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2012-06-28
19:58:01 UTC (rev 4211)
+++ trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -40,7 +40,9 @@
import org.teiid.client.util.ExceptionUtil;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.jdbc.EmbeddedProfile;
import org.teiid.net.CommunicationException;
import org.teiid.net.ConnectionException;
import org.teiid.net.ServerConnection;
@@ -71,8 +73,12 @@
vdbName = vdbName.substring(0, firstIndex);
}
if (vdbVersion != null) {
- this.csr.waitForFinished(connectionProperties.getProperty(TeiidURL.JDBC.VDB_NAME),
Integer.valueOf(vdbVersion));
+ int waitForLoad = PropertiesUtils.getIntProperty(connectionProperties,
EmbeddedProfile.WAIT_FOR_LOAD, -1);
+ if (waitForLoad != 0) {
+ this.csr.waitForFinished(vdbName, Integer.valueOf(vdbVersion), waitForLoad);
+ }
}
+
workContext.setSecurityHelper(csr.getSecurityHelper());
workContext.setUseCallingThread(useCallingThread);
authenticate();
Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2012-06-28 19:58:01
UTC (rev 4211)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2012-06-28 20:02:25
UTC (rev 4212)
@@ -97,3 +97,6 @@
TEIID40092=Policy {0} not found in VDB {1}.{2}
TEIID40093=Model {0} specified with no source information in VDB {1}.{2}
TEIID40094=No metadata repository of type {3} defined for model {0} for VDB {1}.{2}
+
+TEIID40096=Waited {0} for VDB {1}.{2} to be deployed, but it never was. Please check to
see if the deployment is missing or is in error.
+TEIID40097=Waited {0} for VDB {1}.{2} to be ACTIVE, but it never was. Please check
it's sources - {3}.
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-06-28
19:58:01 UTC (rev 4211)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -75,6 +75,7 @@
@SuppressWarnings("serial")
public FakeServer(boolean start) {
+ waitForLoad = true;
cmr = new ProviderAwareConnectorManagerRepository() {
@Override
public ConnectorManager getConnectorManager(String connectorName) {
Modified:
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2012-06-28
19:58:01 UTC (rev 4211)
+++
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2012-06-28
20:02:25 UTC (rev 4212)
@@ -43,6 +43,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.client.util.ResultsFuture;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
@@ -336,4 +337,34 @@
}
}
+ @Test public void testWaitForLoad() throws Exception {
+ final ResultsFuture<Void> future = new ResultsFuture<Void>();
+
+ Thread t = new Thread() {
+ public void run() {
+ try {
+ server.createConnection("jdbc:teiid:not_there.1");
+ future.getResultsReceiver().receiveResults(null);
+ } catch (Exception e) {
+ future.getResultsReceiver().exceptionOccurred(e);
+ }
+ }
+ };
+ t.setDaemon(true);
+ t.start();
+ assertFalse(future.isDone());
+ try {
+ server.deployVDB("not_there", UnitTestUtil.getTestDataPath() +
"/PartsSupplier.vdb");
+ future.get(5000, TimeUnit.SECONDS);
+ } finally {
+ server.undeployVDB("not_there");
+ }
+ try {
+ server.createConnection("jdbc:teiid:not_there.1;waitForLoad=0");
+ fail();
+ } catch (TeiidSQLException e) {
+
+ }
+ }
+
}