forked from djatlantic/gohadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgohadoop.go
98 lines (84 loc) · 2.68 KB
/
gohadoop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package gohadoop
import (
"bytes"
"encoding/binary"
"github.com/hortonworks/gohadoop/hadoop_common"
"log"
"os/user"
"runtime"
"strings"
"unicode"
)
var (
RPC_HEADER []byte = []byte("hrpc")
VERSION []byte = []byte{0x09}
RPC_SERVICE_CLASS byte = 0x00
RPC_PROTOCOL_BUFFFER hadoop_common.RpcKindProto = hadoop_common.RpcKindProto_RPC_PROTOCOL_BUFFER
RPC_FINAL_PACKET hadoop_common.RpcRequestHeaderProto_OperationProto = hadoop_common.RpcRequestHeaderProto_RPC_FINAL_PACKET
RPC_DEFAULT_RETRY_COUNT int32 = hadoop_common.Default_RpcRequestHeaderProto_RetryCount
CLIENT_PROTOCOL_VERSION uint64 = 1
)
type AuthMethod byte
const (
AUTH_SIMPLE AuthMethod = 0x50
AUTH_KERBEROS AuthMethod = 0x51
AUTH_TOKEN AuthMethod = 0x52
AUTH_PLAIN AuthMethod = 0x53
)
func (authmethod AuthMethod) String() string {
switch {
case authmethod == AUTH_SIMPLE:
return "SIMPLE"
case authmethod == AUTH_KERBEROS:
return "GSSAPI"
case authmethod == AUTH_TOKEN:
return "DIGEST-MD5"
case authmethod == AUTH_PLAIN:
return "PLAIN"
}
return "ERROR-UNKNOWN"
}
type AuthProtocol byte
const (
AUTH_PROTOCOL_NONE AuthProtocol = 0x00
AUTH_PROTOCOL_SASL AuthProtocol = 0xDF
)
func (authprotocol AuthProtocol) String() string {
switch {
case authprotocol == AUTH_PROTOCOL_NONE:
return "NONE"
case authprotocol == AUTH_PROTOCOL_SASL:
return "SASL"
}
return "ERROR-UNKNOWN"
}
func ConvertFixedToBytes(data interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
err := binary.Write(buf, binary.BigEndian, data)
return buf.Bytes(), err
}
func ConvertBytesToFixed(rawBytes []byte, data interface{}) error {
buf := bytes.NewBuffer(rawBytes)
err := binary.Read(buf, binary.BigEndian, data)
return err
}
func GetCalleeRPCRequestHeaderProto(protocolName *string) *hadoop_common.RequestHeaderProto {
pc, _, _, _ := runtime.Caller(1) // Callee Method Name
fullName := runtime.FuncForPC(pc).Name()
names := strings.Split(fullName, ".")
unicodeName := []rune(names[len(names)-1])
unicodeName[0] = unicode.ToLower(unicodeName[0])
methodName := string(unicodeName)
return &hadoop_common.RequestHeaderProto{MethodName: &methodName, DeclaringClassProtocolName: protocolName, ClientProtocolVersion: &CLIENT_PROTOCOL_VERSION}
}
func CreateSimpleUGIProto() (*hadoop_common.UserInformationProto, error) {
// Figure the current user-name
var username string
if user, err := user.Current(); err != nil {
log.Fatal("user.Current", err)
return nil, err
} else {
username = user.Username
}
return &hadoop_common.UserInformationProto{EffectiveUser: nil, RealUser: &username}, nil
}