Search in sources :

Example 1 with RequestMetadata

use of org.teiid.adminapi.impl.RequestMetadata in project teiid by teiid.

the class TestDQPCoreRequestHandling method testGetRequestsSessionToken2.

/**
 * Test for Collection getRequests(SessionToken) - 1 request
 */
public void testGetRequestsSessionToken2() {
    DQPCore rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    Set<RequestID> reqs = new HashSet<RequestID>();
    RequestID id = addRequest(rm, SESSION_STRING, 1);
    reqs.add(id);
    Collection<RequestMetadata> actualReqs = rm.getRequestsForSession(SESSION_STRING);
    compareReqInfos(reqs, actualReqs);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) HashSet(java.util.HashSet) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata)

Example 2 with RequestMetadata

use of org.teiid.adminapi.impl.RequestMetadata in project teiid by teiid.

the class TestRequestMetadata method testMapping.

@Test
public void testMapping() {
    RequestMetadata request = buildRequest();
    ModelNode node = VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, new ModelNode());
    RequestMetadata actual = VDBMetadataMapper.RequestMetadataMapper.INSTANCE.unwrap(node);
    assertEquals(request, actual);
    assertEquals(request.getState(), actual.getState());
}
Also used : ModelNode(org.jboss.dmr.ModelNode) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata) Test(org.junit.Test)

Example 3 with RequestMetadata

use of org.teiid.adminapi.impl.RequestMetadata in project teiid by teiid.

the class DQPCore method buildRequestInfos.

private List<RequestMetadata> buildRequestInfos(Collection<RequestID> ids, long longRunningQueryThreshold) {
    List<RequestMetadata> results = new ArrayList<RequestMetadata>();
    for (RequestID requestID : ids) {
        RequestWorkItem holder = requests.get(requestID);
        if (holder != null && !holder.isCanceled() && (longRunningQueryThreshold == -1 || holder.getProcessingTimestamp() < longRunningQueryThreshold)) {
            RequestMetadata req = new RequestMetadata();
            req.setExecutionId(holder.requestID.getExecutionID());
            req.setSessionId(holder.requestID.getConnectionID());
            req.setCommand(holder.requestMsg.getCommandString());
            req.setStartTime(holder.getProcessingTimestamp());
            req.setState(holder.isCanceled() ? ProcessingState.CANCELED : (holder.isDoneProcessing() || holder.isCloseRequested()) ? ProcessingState.DONE : ProcessingState.PROCESSING);
            switch(holder.getThreadState()) {
                case DONE:
                case IDLE:
                    req.setThreadState(ThreadState.IDLE);
                    break;
                default:
                    if (holder.isProcessing()) {
                        req.setThreadState(ThreadState.RUNNING);
                    } else {
                        req.setThreadState(ThreadState.QUEUED);
                    }
            }
            if (holder.getTransactionContext() != null && holder.getTransactionContext().getTransactionType() != Scope.NONE) {
                req.setTransactionId(holder.getTransactionContext().getTransactionId());
            }
            for (DataTierTupleSource conInfo : holder.getConnectorRequests()) {
                String connectorName = conInfo.getConnectorName();
                if (connectorName == null) {
                    continue;
                }
                // If the request has not yet completed processing, then
                // add all the subrequest messages
                AtomicRequestMessage arm = conInfo.getAtomicRequestMessage();
                RequestMetadata info = new RequestMetadata();
                if (conInfo.isQueued()) {
                    info.setThreadState(ThreadState.QUEUED);
                } else if (conInfo.isRunning()) {
                    info.setThreadState(ThreadState.RUNNING);
                } else {
                    info.setThreadState(ThreadState.IDLE);
                }
                info.setExecutionId(arm.getRequestID().getExecutionID());
                info.setSessionId(holder.requestID.getConnectionID());
                info.setCommand(arm.getCommand().toString());
                info.setStartTime(arm.getProcessingTimestamp());
                info.setSourceRequest(true);
                info.setNodeId(arm.getAtomicRequestID().getNodeID());
                info.setState(conInfo.isCanceled() ? ProcessingState.CANCELED : conInfo.isDone() ? ProcessingState.DONE : ProcessingState.PROCESSING);
                results.add(info);
            }
            results.add(req);
        }
    }
    return results;
}
Also used : RequestID(org.teiid.dqp.message.RequestID) ArrayList(java.util.ArrayList) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata)

Example 4 with RequestMetadata

use of org.teiid.adminapi.impl.RequestMetadata in project teiid by teiid.

the class TestDQPCoreRequestHandling method compareReqInfos.

private void compareReqInfos(Collection<RequestID> reqs1, Collection<RequestMetadata> reqs2) {
    Set<RequestID> reqIDs2 = new HashSet<RequestID>();
    for (RequestMetadata requestInfo : reqs2) {
        reqIDs2.add(new RequestID(requestInfo.getSessionId(), requestInfo.getExecutionId()));
    }
    // $NON-NLS-1$
    assertEquals("Collections of request infos are not the same: ", new HashSet<RequestID>(reqs1), reqIDs2);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) HashSet(java.util.HashSet) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata)

Example 5 with RequestMetadata

use of org.teiid.adminapi.impl.RequestMetadata in project teiid by teiid.

the class TestDQPCoreRequestHandling method testGetRequestsSessionToken3.

/**
 * Test for Collection getRequests(SessionToken) - 3 requests
 */
public void testGetRequestsSessionToken3() {
    DQPCore rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    Set<RequestID> reqs = new HashSet<RequestID>();
    reqs.add(addRequest(rm, SESSION_STRING, 0));
    reqs.add(addRequest(rm, SESSION_STRING, 1));
    reqs.add(addRequest(rm, SESSION_STRING, 2));
    Collection<RequestMetadata> actualReqs = rm.getRequestsForSession(SESSION_STRING);
    compareReqInfos(reqs, actualReqs);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) HashSet(java.util.HashSet) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata)

Aggregations

RequestMetadata (org.teiid.adminapi.impl.RequestMetadata)8 RequestID (org.teiid.dqp.message.RequestID)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ModelNode (org.jboss.dmr.ModelNode)1 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)1