// DialTablet creates and initializes TabletBson. func DialTablet(ctx context.Context, endPoint topo.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) { var addr string var config *tls.Config if *tabletBsonEncrypted { addr = netutil.JoinHostPort(endPoint.Host, endPoint.NamedPortMap["vts"]) config = &tls.Config{} config.InsecureSkipVerify = true } else { addr = netutil.JoinHostPort(endPoint.Host, endPoint.NamedPortMap["vt"]) } conn := &TabletBson{endPoint: endPoint} var err error if *tabletBsonUsername != "" { conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout, config) } else { conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout, config) } if err != nil { return nil, tabletError(err) } var sessionInfo tproto.SessionInfo if err = conn.rpcClient.Call(ctx, "SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil { conn.rpcClient.Close() return nil, tabletError(err) } // SqlQuery.GetSessionId might return an application error inside the SessionInfo if err = vterrors.FromRPCError(sessionInfo.Err); err != nil { conn.rpcClient.Close() return nil, tabletError(err) } conn.sessionID = sessionInfo.SessionId return conn, nil }
// DialTablet creates and initializes TabletBson. func DialTablet(context context.Context, endPoint topo.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) { var addr string var config *tls.Config if *tabletBsonEncrypted { addr = fmt.Sprintf("%v:%v", endPoint.Host, endPoint.NamedPortMap["_vts"]) config = &tls.Config{} config.InsecureSkipVerify = true } else { addr = fmt.Sprintf("%v:%v", endPoint.Host, endPoint.NamedPortMap["_vtocc"]) } conn := &TabletBson{endPoint: endPoint} var err error if *tabletBsonUsername != "" { conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout, config) } else { conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout, config) } if err != nil { return nil, tabletError(err) } var sessionInfo tproto.SessionInfo if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil { conn.rpcClient.Close() return nil, tabletError(err) } conn.sessionID = sessionInfo.SessionId return conn, nil }
// DialTablet creates and initializes TabletBson. func DialTablet(ctx context.Context, endPoint *pbt.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) { addr := netutil.JoinHostPort(endPoint.Host, endPoint.PortMap["vt"]) conn := &TabletBson{endPoint: endPoint} var err error if *tabletBsonUsername != "" { conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout) } else { conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout) } if err != nil { return nil, tabletError(err) } if keyspace != "" || shard != "" { var sessionInfo tproto.SessionInfo if err = conn.rpcClient.Call(ctx, "SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil { conn.rpcClient.Close() return nil, tabletError(err) } // SqlQuery.GetSessionId might return an application error inside the SessionInfo if err = vterrors.FromRPCError(sessionInfo.Err); err != nil { conn.rpcClient.Close() return nil, tabletError(err) } conn.sessionID = sessionInfo.SessionId } return conn, nil }
func DialTablet(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error) { // FIXME(sougou/shrutip): Add encrypted support conn := new(TabletBson) var err error if username != "" { conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, username, password, 0) } else { conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, 0) } if err != nil { return nil, err } var sessionInfo tproto.SessionInfo if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil { return nil, err } conn.session.SessionId = sessionInfo.SessionId return conn, nil }
func (conn *Conn) dial() (err error) { user, password, useAuth, err := conn.authCredentials() if err != nil { return err } if useAuth { conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", conn.dbi.Host, user, password, 0) } else { conn.rpcClient, err = bsonrpc.DialHTTP("tcp", conn.dbi.Host, 0) } if err != nil { return } var sessionInfo tproto.SessionInfo if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: conn.keyspace(), Shard: conn.shard()}, &sessionInfo); err != nil { return } conn.SessionId = sessionInfo.SessionId return }