teiid SVN: r2621 - in branches/7.1.x: client/src/main/java/org/teiid/adminapi and 10 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-10-01 11:43:39 -0400 (Fri, 01 Oct 2010)
New Revision: 2621
Modified:
branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
branches/7.1.x/client/src/main/java/org/teiid/adminapi/Admin.java
branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java
branches/7.1.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
branches/7.1.x/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
branches/7.1.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
branches/7.1.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java
branches/7.1.x/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java
branches/7.1.x/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java
Log:
TEIID-982: adding a facility to execute a SQL command over the management api, so the JOPR tool can issue admin specific sql commands to manage the Teiid runtime.
Modified: branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -132,9 +132,9 @@
@Doc(text = "Cancel a request")
public static void cancelRequest(
@Doc(text = "session id") String sessionId,
- @Doc(text = "request id") long requestId)
+ @Doc(text = "execution id") long executionId)
throws AdminException {
- getAdmin().cancelRequest(sessionId, requestId);
+ getAdmin().cancelRequest(sessionId, executionId);
}
@Doc(text = "Clear the given cache")
Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/adminapi/Admin.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/client/src/main/java/org/teiid/adminapi/Admin.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -211,11 +211,11 @@
* Cancel Request
*
* @param sessionId session Identifier for the request.
- * @param requestId request Identifier
+ * @param executionId request Identifier
*
* @throws AdminException
*/
- void cancelRequest(String sessionId, long requestId) throws AdminException;
+ void cancelRequest(String sessionId, long executionId) throws AdminException;
/**
* Mark the given global transaction as rollback only.
Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -43,4 +43,5 @@
List<RequestMetadata> getLongRunningRequests();
List<RequestMetadata> getRequestsUsingVDB(String vdbName, int vdbVersion) throws AdminException;
CacheStatisticsMetadata getCacheStatistics(String cacheType);
+ List<List> executeQuery(String vdbName, int version, String command, long timoutInMilli) throws AdminException;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -497,8 +497,8 @@
}
}
- public boolean cancelRequest(String sessionId, long requestId) throws TeiidComponentException {
- RequestID requestID = new RequestID(sessionId, requestId);
+ public boolean cancelRequest(String sessionId, long executionId) throws TeiidComponentException {
+ RequestID requestID = new RequestID(sessionId, executionId);
return cancelRequest(requestID);
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -561,7 +561,7 @@
public boolean requestCancel() throws TeiidComponentException {
synchronized (this) {
- if (this.isCanceled) {
+ if (this.isCanceled || this.closeRequested) {
return false;
}
this.isCanceled = true;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -66,7 +66,7 @@
public SessionMetadata createSession(String userName,
Credentials credentials,
String applicationName,
- Properties properties, boolean admin)
+ Properties properties, boolean admin, boolean authenticate)
throws LoginException, SessionServiceException;
/**
Modified: branches/7.1.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- branches/7.1.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -293,10 +293,10 @@
}
@Override
- public void cancelRequest(String sessionId, long requestId) throws AdminException{
+ public void cancelRequest(String sessionId, long executionId) throws AdminException{
try {
ManagedComponent mc = getView().getComponent(DQPNAME, DQPTYPE);
- ManagedUtil.executeOperation(mc, "cancelRequest", SimpleValueSupport.wrap(sessionId), SimpleValueSupport.wrap(requestId));//$NON-NLS-1$
+ ManagedUtil.executeOperation(mc, "cancelRequest", SimpleValueSupport.wrap(sessionId), SimpleValueSupport.wrap(executionId));//$NON-NLS-1$
} catch (Exception e) {
throw new AdminComponentException(e.getMessage(), e);
}
Modified: branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
--- branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -26,14 +26,20 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.resource.spi.XATerminator;
import javax.resource.spi.work.WorkManager;
+import javax.security.auth.login.LoginException;
import javax.transaction.TransactionManager;
import org.jboss.managed.api.ManagedOperation.Impact;
@@ -49,6 +55,7 @@
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminComponentException;
import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Admin.Cache;
import org.teiid.adminapi.impl.CacheStatisticsMetadata;
import org.teiid.adminapi.impl.DQPManagement;
@@ -58,8 +65,12 @@
import org.teiid.adminapi.jboss.AdminProvider;
import org.teiid.cache.CacheFactory;
import org.teiid.client.DQP;
+import org.teiid.client.RequestMessage;
+import org.teiid.client.ResultsMessage;
import org.teiid.client.security.ILogon;
+import org.teiid.client.security.InvalidSessionException;
import org.teiid.client.util.ExceptionUtil;
+import org.teiid.client.util.ResultsFuture;
import org.teiid.core.ComponentNotFoundException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
@@ -78,6 +89,7 @@
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
+import org.teiid.net.TeiidURL;
import org.teiid.security.SecurityHelper;
import org.teiid.transport.ClientServiceRegistry;
import org.teiid.transport.ClientServiceRegistryImpl;
@@ -395,10 +407,10 @@
}
@Override
- @ManagementOperation(description="Cancel a Request",params={@ManagementParameter(name="sessionId",description="The session Identifier"), @ManagementParameter(name="requestId",description="The request Identifier")})
- public boolean cancelRequest(String sessionId, long requestId) throws AdminException {
+ @ManagementOperation(description="Cancel a Request",params={@ManagementParameter(name="sessionId",description="The session Identifier"), @ManagementParameter(name="executionId",description="The Execution Identifier")})
+ public boolean cancelRequest(String sessionId, long executionId) throws AdminException {
try {
- return this.dqpCore.cancelRequest(sessionId, requestId);
+ return this.dqpCore.cancelRequest(sessionId, executionId);
} catch (TeiidComponentException e) {
throw new AdminComponentException(e);
}
@@ -464,4 +476,77 @@
public void setCacheFactory(CacheFactory factory) {
this.dqpCore.setCacheFactory(factory);
}
+
+ @Override
+ @ManagementOperation(description="Execute a sql query", params={@ManagementParameter(name="vdbName"),@ManagementParameter(name="vdbVersion"), @ManagementParameter(name="command")})
+ public List<List> executeQuery(final String vdbName, final int version, final String command, final long timoutInMilli) throws AdminException {
+ Properties properties = new Properties();
+ properties.setProperty(TeiidURL.JDBC.VDB_NAME, vdbName);
+ properties.setProperty(TeiidURL.JDBC.VDB_VERSION, String.valueOf(version));
+
+ String user = "JOPR ADMIN"; //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.getString("admin_executing", user, command)); //$NON-NLS-1$
+
+ SessionMetadata session = null;
+ try {
+ session = this.sessionService.createSession(user, null, "JOPR", properties, false, false); //$NON-NLS-1$
+ } catch (SessionServiceException e1) {
+ throw new AdminProcessingException(e1);
+ } catch (LoginException e1) {
+ throw new AdminProcessingException(e1);
+ }
+
+ final long requestID = 0L;
+
+ DQPWorkContext context = new DQPWorkContext();
+ context.setSession(session);
+
+ try {
+ return context.runInContext(new Callable<List<List>>() {
+ @Override
+ public List<List> call() throws Exception {
+ ArrayList<List> results = new ArrayList<List>();
+
+ long start = System.currentTimeMillis();
+ RequestMessage request = new RequestMessage(command);
+ request.setExecutionId(0L);
+ request.setRowLimit(getMaxRowsFetchSize()); // this would limit the number of rows that are returned.
+ Future<ResultsMessage> message = dqpCore.executeRequest(requestID, request);
+ ResultsMessage rm = message.get(timoutInMilli, TimeUnit.MILLISECONDS);
+
+ if (rm.getException() != null) {
+ throw new AdminProcessingException(rm.getException());
+ }
+
+ if (rm.isUpdateResult()) {
+ results.addAll(new ArrayList(Arrays.asList("update count"))); //$NON-NLS-1$
+ results.addAll(Arrays.asList(rm.getResults()));
+ }
+ else {
+ results.addAll(new ArrayList(Arrays.asList(rm.getColumnNames())));
+ results.addAll(Arrays.asList(rm.getResults()));
+
+ while (rm.getFinalRow() == -1 || rm.getLastRow() < rm.getFinalRow()) {
+ long elapsed = System.currentTimeMillis() - start;
+ message = dqpCore.processCursorRequest(requestID, rm.getLastRow()+1, 1024);
+ rm = message.get(timoutInMilli-elapsed, TimeUnit.MILLISECONDS);
+ results.addAll(Arrays.asList(rm.getResults()));
+ }
+ }
+
+ long elapsed = System.currentTimeMillis() - start;
+ ResultsFuture<?> response = dqpCore.closeRequest(requestID);
+ response.get(timoutInMilli-elapsed, TimeUnit.MILLISECONDS);
+ return results;
+ }
+ });
+ } catch (Throwable t) {
+ throw new AdminProcessingException(t);
+ } finally {
+ try {
+ sessionService.closeSession(session.getSessionId());
+ } catch (InvalidSessionException e) { //ignore
+ }
+ }
+ }
}
Modified: branches/7.1.x/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- branches/7.1.x/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2010-10-01 15:43:39 UTC (rev 2621)
@@ -45,3 +45,4 @@
jndi_failed=JNDI lookup failed.
distribute_failed=Deploy of the archive failed {0}
template_not_found=Template not found for {0}
+admin_executing=JOPR admin {0} is executing command {1}
Modified: branches/7.1.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- branches/7.1.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -136,7 +136,7 @@
}
@Override
- public SessionMetadata createSession(String userName, Credentials credentials, String applicationName, Properties properties, boolean adminConnection)
+ public SessionMetadata createSession(String userName, Credentials credentials, String applicationName, Properties properties, boolean adminConnection, boolean authenticate)
throws LoginException, SessionServiceException {
ArgCheck.isNotNull(applicationName);
ArgCheck.isNotNull(properties);
@@ -161,7 +161,7 @@
throw new SessionServiceException(RuntimePlugin.Util.getString("SessionServiceImpl.reached_max_sessions", new Object[] {new Long(sessionMaxLimit)})); //$NON-NLS-1$
}
- if (!domains.isEmpty()) {
+ if (!domains.isEmpty() && authenticate) {
// Authenticate user...
// if not authenticated, this method throws exception
boolean onlyAllowPassthrough = Boolean.valueOf(properties.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); //$NON-NLS-1$
Modified: branches/7.1.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java
===================================================================
--- branches/7.1.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -72,7 +72,7 @@
boolean adminConnection = Boolean.parseBoolean(connProps.getProperty(TeiidURL.CONNECTION.ADMIN));
try {
- SessionMetadata sessionInfo = service.createSession(user,credential, applicationName, connProps, adminConnection);
+ SessionMetadata sessionInfo = service.createSession(user,credential, applicationName, connProps, adminConnection, true);
updateDQPContext(sessionInfo);
if (DQPWorkContext.getWorkContext().getClientAddress() == null) {
sessionInfo.setEmbedded(true);
Modified: branches/7.1.x/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java
===================================================================
--- branches/7.1.x/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -51,7 +51,7 @@
}
- SessionMetadata info = ssi.createSession("steve", null, "foo", new Properties(), false); //$NON-NLS-1$ //$NON-NLS-2$
+ SessionMetadata info = ssi.createSession("steve", null, "foo", new Properties(), false, true); //$NON-NLS-1$ //$NON-NLS-2$
if (securityEnabled) {
Mockito.verify(impl).authenticateUser("steve", null, "foo", domains, false);
}
Modified: branches/7.1.x/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java
===================================================================
--- branches/7.1.x/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java 2010-09-30 18:43:06 UTC (rev 2620)
+++ branches/7.1.x/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java 2010-10-01 15:43:39 UTC (rev 2621)
@@ -53,7 +53,7 @@
session.setSessionId(String.valueOf(1));
session.setSessionToken(new SessionToken(1, userName));
- Mockito.stub(ssi.createSession(userName, null, applicationName,p, false)).toReturn(session);
+ Mockito.stub(ssi.createSession(userName, null, applicationName,p, false, true)).toReturn(session);
LogonImpl impl = new LogonImpl(ssi, "fakeCluster"); //$NON-NLS-1$
14 years, 2 months