Search in sources :

Example 1 with BinaryHeapInputStream

use of org.apache.ignite.internal.binary.streams.BinaryHeapInputStream in project ignite by apache.

the class SqlListenerNioListener method onHandshake.

/**
     * Perform handshake.
     *
     * @param ses Session.
     * @param msg Message bytes.
     */
private void onHandshake(GridNioSession ses, byte[] msg) {
    BinaryInputStream stream = new BinaryHeapInputStream(msg);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null, true);
    byte cmd = reader.readByte();
    if (cmd != SqlListenerRequest.HANDSHAKE) {
        log.error("Unexpected SQL client request (will close session): " + ses.remoteAddress());
        ses.close();
        return;
    }
    short verMajor = reader.readShort();
    short verMinor = reader.readShort();
    short verMaintenance = reader.readShort();
    SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(verMajor, verMinor, verMaintenance);
    String errMsg = null;
    if (SUPPORTED_VERS.contains(ver)) {
        // Prepare context.
        SqlListenerConnectionContext connCtx = prepareContext(ver, reader);
        ses.addMeta(CONN_CTX_META_KEY, connCtx);
    } else {
        log.warning("Unsupported version: " + ver.toString());
        errMsg = "Unsupported version.";
    }
    // Send response.
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
    if (errMsg == null)
        writer.writeBoolean(true);
    else {
        writer.writeBoolean(false);
        writer.writeShort(CURRENT_VER.major());
        writer.writeShort(CURRENT_VER.minor());
        writer.writeShort(CURRENT_VER.maintenance());
        writer.doWriteString(errMsg);
    }
    ses.send(writer.array());
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 2 with BinaryHeapInputStream

use of org.apache.ignite.internal.binary.streams.BinaryHeapInputStream in project ignite by apache.

the class JdbcThinTcpIo method handshake.

/**
     * @throws IOException On error.
     * @throws IgniteCheckedException On error.
     */
public void handshake() throws IOException, IgniteCheckedException {
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
    writer.writeByte((byte) SqlListenerRequest.HANDSHAKE);
    writer.writeShort(CURRENT_VER.major());
    writer.writeShort(CURRENT_VER.minor());
    writer.writeShort(CURRENT_VER.maintenance());
    writer.writeByte(SqlListenerNioListener.JDBC_CLIENT);
    writer.writeBoolean(distributedJoins);
    writer.writeBoolean(enforceJoinOrder);
    send(writer.array());
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, new BinaryHeapInputStream(read()), null, null, false);
    boolean accepted = reader.readBoolean();
    if (accepted)
        return;
    short maj = reader.readShort();
    short min = reader.readShort();
    short maintenance = reader.readShort();
    String err = reader.readString();
    SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(maj, min, maintenance);
    throw new IgniteCheckedException("Handshake failed [driverProtocolVer=" + CURRENT_VER + ", remoteNodeProtocolVer=" + ver + ", err=" + err + ']');
}
Also used : SqlListenerProtocolVersion(org.apache.ignite.internal.processors.odbc.SqlListenerProtocolVersion) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 3 with BinaryHeapInputStream

use of org.apache.ignite.internal.binary.streams.BinaryHeapInputStream in project ignite by apache.

the class ClientMessageParser method decode.

/**
 * {@inheritDoc}
 */
@Override
public ClientListenerRequest decode(byte[] msg) {
    assert msg != null;
    BinaryInputStream inStream = new BinaryHeapInputStream(msg);
    // skipHdrCheck must be true (we have 103 op code).
    BinaryRawReaderEx reader = new BinaryReaderExImpl(marsh.context(), inStream, null, null, true, true);
    return decode(reader);
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx)

Example 4 with BinaryHeapInputStream

use of org.apache.ignite.internal.binary.streams.BinaryHeapInputStream in project ignite by apache.

the class ClientListenerNioListener method onHandshake.

/**
 * Perform handshake.
 *
 * @param ses Session.
 * @param msg Message bytes.
 */
private void onHandshake(GridNioSession ses, byte[] msg) {
    BinaryInputStream stream = new BinaryHeapInputStream(msg);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null, true);
    byte cmd = reader.readByte();
    if (cmd != ClientListenerRequest.HANDSHAKE) {
        log.error("Unexpected client request (will close session): " + ses.remoteAddress());
        ses.close();
        return;
    }
    short verMajor = reader.readShort();
    short verMinor = reader.readShort();
    short verMaintenance = reader.readShort();
    ClientListenerProtocolVersion ver = ClientListenerProtocolVersion.create(verMajor, verMinor, verMaintenance);
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
    byte clientType = reader.readByte();
    ClientListenerConnectionContext connCtx = null;
    try {
        connCtx = prepareContext(clientType);
        ensureClientPermissions(clientType);
        if (connCtx.isVersionSupported(ver)) {
            connCtx.initializeFromHandshake(ver, reader);
            ses.addMeta(CONN_CTX_META_KEY, connCtx);
        } else {
            log.warning("Unsupported version: " + ver.toString());
            throw new IgniteCheckedException("Unsupported version.");
        }
        connCtx.handler().writeHandshake(writer);
    } catch (IgniteCheckedException e) {
        log.error("Error on handshake. " + e.getMessage(), e);
        ClientListenerProtocolVersion currVer;
        if (connCtx == null)
            currVer = ClientListenerProtocolVersion.create(0, 0, 0);
        else
            currVer = connCtx.currentVersion();
        writer.writeBoolean(false);
        writer.writeShort(currVer.major());
        writer.writeShort(currVer.minor());
        writer.writeShort(currVer.maintenance());
        writer.doWriteString(e.getMessage());
    }
    ses.send(writer.array());
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 5 with BinaryHeapInputStream

use of org.apache.ignite.internal.binary.streams.BinaryHeapInputStream in project ignite by apache.

the class OdbcMessageParser method decode.

/**
 * {@inheritDoc}
 */
@Override
public ClientListenerRequest decode(ClientMessage msg) {
    assert msg != null;
    BinaryInputStream stream = new BinaryHeapInputStream(msg.payload());
    BinaryReaderExImpl reader = new BinaryReaderExImpl(marsh.context(), stream, ctx.config().getClassLoader(), true);
    byte cmd = reader.readByte();
    ClientListenerRequest res;
    switch(cmd) {
        case OdbcRequest.QRY_EXEC:
            {
                String schema = reader.readString();
                String sql = reader.readString();
                int paramNum = reader.readInt();
                Object[] params = readParameterRow(reader, paramNum);
                int timeout = 0;
                if (ver.compareTo(OdbcConnectionContext.VER_2_3_2) >= 0)
                    timeout = reader.readInt();
                boolean autoCommit = true;
                if (ver.compareTo(OdbcConnectionContext.VER_2_7_0) >= 0)
                    autoCommit = reader.readBoolean();
                res = new OdbcQueryExecuteRequest(schema, sql, params, timeout, autoCommit);
                break;
            }
        case OdbcRequest.QRY_EXEC_BATCH:
            {
                String schema = reader.readString();
                String sql = reader.readString();
                int paramRowLen = reader.readInt();
                int rowNum = reader.readInt();
                boolean last = reader.readBoolean();
                Object[][] params = new Object[rowNum][];
                for (int i = 0; i < rowNum; ++i) params[i] = readParameterRow(reader, paramRowLen);
                int timeout = 0;
                if (ver.compareTo(OdbcConnectionContext.VER_2_3_2) >= 0)
                    timeout = reader.readInt();
                boolean autoCommit = true;
                if (ver.compareTo(OdbcConnectionContext.VER_2_7_0) >= 0)
                    autoCommit = reader.readBoolean();
                res = new OdbcQueryExecuteBatchRequest(schema, sql, last, params, timeout, autoCommit);
                break;
            }
        case OdbcRequest.STREAMING_BATCH:
            {
                String schema = reader.readString();
                int num = reader.readInt();
                ArrayList<OdbcQuery> queries = new ArrayList<>(num);
                for (int i = 0; i < num; ++i) {
                    OdbcQuery qry = new OdbcQuery();
                    qry.readBinary(reader);
                    queries.add(qry);
                }
                boolean last = reader.readBoolean();
                long order = reader.readLong();
                res = new OdbcStreamingBatchRequest(schema, queries, last, order);
                break;
            }
        case OdbcRequest.QRY_FETCH:
            {
                long queryId = reader.readLong();
                int pageSize = reader.readInt();
                res = new OdbcQueryFetchRequest(queryId, pageSize);
                break;
            }
        case OdbcRequest.QRY_CLOSE:
            {
                long queryId = reader.readLong();
                res = new OdbcQueryCloseRequest(queryId);
                break;
            }
        case OdbcRequest.META_COLS:
            {
                String schema = reader.readString();
                String table = reader.readString();
                String column = reader.readString();
                res = new OdbcQueryGetColumnsMetaRequest(schema, table, column);
                break;
            }
        case OdbcRequest.META_TBLS:
            {
                String catalog = reader.readString();
                String schema = reader.readString();
                String table = reader.readString();
                String tableType = reader.readString();
                res = new OdbcQueryGetTablesMetaRequest(catalog, schema, table, tableType);
                break;
            }
        case OdbcRequest.META_PARAMS:
            {
                String schema = reader.readString();
                String sqlQuery = reader.readString();
                res = new OdbcQueryGetParamsMetaRequest(schema, sqlQuery);
                break;
            }
        case OdbcRequest.META_RESULTSET:
            {
                String schema = reader.readString();
                String sqlQuery = reader.readString();
                res = new OdbcQueryGetResultsetMetaRequest(schema, sqlQuery);
                break;
            }
        case OdbcRequest.MORE_RESULTS:
            {
                long queryId = reader.readLong();
                int pageSize = reader.readInt();
                res = new OdbcQueryMoreResultsRequest(queryId, pageSize);
                break;
            }
        default:
            throw new IgniteException("Unknown ODBC command: [cmd=" + cmd + ']');
    }
    return res;
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) ArrayList(java.util.ArrayList) ClientListenerRequest(org.apache.ignite.internal.processors.odbc.ClientListenerRequest) IgniteException(org.apache.ignite.IgniteException) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)

Aggregations

BinaryHeapInputStream (org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)16 BinaryReaderExImpl (org.apache.ignite.internal.binary.BinaryReaderExImpl)13 BinaryHeapOutputStream (org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream)9 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)8 BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 JdbcResponse (org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse)3 SQLException (java.sql.SQLException)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)2 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 ClientListenerProtocolVersion (org.apache.ignite.internal.processors.odbc.ClientListenerProtocolVersion)2 ClientListenerRequest (org.apache.ignite.internal.processors.odbc.ClientListenerRequest)2 IgniteProductVersion (org.apache.ignite.lang.IgniteProductVersion)2 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1