Skip to content

Commit

Permalink
api: add proto and rm admin client (koordinator-sh#1)
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <[email protected]>
  • Loading branch information
zwzhang0107 authored Jun 6, 2023
1 parent f0a168b commit 7ebe7c1
Show file tree
Hide file tree
Showing 49 changed files with 23,424 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~

.vscode
.DS_Store

dist/
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# goyarn
use goyarn as native go clients for Apache Hadoop YARN.

It includes an early version of Hadoop IPC client and requisite YARN client libraries to implement YARN applications completely in go (both YARN application-client and application-master).

Koordinator extends `github.com/hortonworks/gohadoop` by implementing resource manager administration service and other clients.

# Notes:
Set HADOOP_CONF_DIR environment variable, and ensure the conf directory contains both *-default.xml and *-site.xml files.
rm_update_node_resource.go is an example go YARN rpc client of rm-admin: call update node resource to do the updates.

# Run rm_update_node_resource
change the `host` and `port` to target node id
$ HADOOP_CONF_DIR=conf go run examples/rm_update_node_resource.go
1 change: 1 addition & 0 deletions apis/VERSIONS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hadoop=release-3.2.1-RC0
116 changes: 116 additions & 0 deletions apis/auth/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright 2013 The Cloudera Inc.
Copyright 2023 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package auth

import (
"bytes"
"encoding/binary"
"log"
"os/user"
"runtime"
"strings"
"unicode"

hadoop_common "github.com/koordinator-sh/goyarn/apis/proto/hadoopcommon"
)

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
}
Loading

0 comments on commit 7ebe7c1

Please sign in to comment.