Skip to content

Commit

Permalink
fixed ports bug, datanode registering in minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
last-saiyan committed Jan 5, 2021
1 parent 53d4d5e commit 58c6bb8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
)

var (
// address = "localhost:8001"
// address = "192.168.99.101:30007"
config = utils.GetConfig()
address = config.NameNodeHost + ":" + config.NameNodePort
address = config.NameNodeHost + config.NameNodePort
)

// Read a file
Expand Down Expand Up @@ -64,10 +62,14 @@ func readBlock(chunkName string, ipAddr string) []byte {
}

func getFileLocation(fileName string, mode proto.FileName_Mode) *proto.FileLocationArr {
fmt.Println("asdfasdf")

conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
fmt.Println("asdfasdf")

defer conn.Close()
c := proto.NewDfsClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Replica": 3,
"EditLog": "editLog",
"DataDir": "data",
"NameNodePort": 8001,
"DataNodePort": 8010,
"NameNodePort": ":8001",
"DataNodePort": ":8010",
"NameNodeHost": "namenode-statefulset-0.namenode-service.default.svc.cluster.local",
"IoSize": 100
}
5 changes: 2 additions & 3 deletions dataNode/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

var (
config = utils.GetConfig()
port = ":" + config.DataNodePort
nameNodeHostURL = "http://" + config.NameNodeHost + ":" + config.NameNodePort
port = config.DataNodePort
nameNodeHostURL = config.NameNodeHost + config.NameNodePort
)

type server struct {
Expand Down Expand Up @@ -73,7 +73,6 @@ func (s *server) WriteBlock(stream proto.Dfs_WriteBlockServer) error {
}

func registerDataNode() error {
fmt.Println("hwllo world")
conn, err := grpc.Dial(nameNodeHostURL, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
Expand Down
4 changes: 3 additions & 1 deletion deployment/datanode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ spec:
containers:
- name: datanode
image: datanode
imagePullPolicy: Never
imagePullPolicy: Never
ports:
- containerPort: 8010
4 changes: 3 additions & 1 deletion deployment/namenode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ spec:
containers:
- name: namenode
image: namenode
imagePullPolicy: Never
imagePullPolicy: Never
ports:
- containerPort: 8001
10 changes: 7 additions & 3 deletions namenode/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
dataNodePort = utils.GetConfig().DataNodePort
nameNodePort = utils.GetConfig().NameNodePort
blockSize = utils.GetConfig().BlockSize
replicaCount = utils.GetConfig().Replica
nn = namenode.NameNode{}
Expand All @@ -26,7 +26,11 @@ type server struct {
}

func (s *server) GetFileLocation(ctx context.Context, in *proto.FileName) (*proto.FileLocationArr, error) {
fmt.Println("getfile")

if proto.FileName_READ == in.Mode {
fmt.Println("getfile")

return nn.GetFileLocation(in.FileName)
} else if proto.FileName_WRITE == in.Mode {
return nn.WriteToFile(in.FileName)
Expand All @@ -52,8 +56,9 @@ func (s *server) RenewLock(ctx context.Context, in *proto.FileName) (*proto.Rene
}

func main() {
nn.Init(blockSize, replicaCount)
utils.GetConfig()
lis, err := net.Listen("tcp", dataNodePort)
lis, err := net.Listen("tcp", nameNodePort)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
Expand All @@ -62,5 +67,4 @@ func main() {
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
nn.Init(blockSize, replicaCount)
}

0 comments on commit 58c6bb8

Please sign in to comment.