You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/04/21 19:47:17 UTC

[GitHub] [ozone-go] elek commented on a change in pull request #6: HDDS-5085. Create initial project structure with importing POC code

elek commented on a change in pull request #6:
URL: https://github.com/apache/ozone-go/pull/6#discussion_r617830983



##########
File path: api/datanode/datanode.go
##########
@@ -0,0 +1,261 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 datanode
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	dnapi "github.com/apache/ozone-go/api/proto/datanode"
+	"github.com/apache/ozone-go/api/proto/hdds"
+	"github.com/apache/ozone-go/api/proto/ratis"
+	"google.golang.org/grpc"
+	"io"
+	"strconv"
+)
+
+type ChunkInfo struct {
+	Name   string
+	Offset uint64
+	Len    uint64
+}
+
+type DatanodeClient struct {
+	ratisClient        *ratis.RaftClientProtocolService_UnorderedClient
+	ratisReceiver      chan ratis.RaftClientReplyProto
+	standaloneClient   *dnapi.XceiverClientProtocolService_SendClient
+	standaloneReceiver chan dnapi.ContainerCommandResponseProto
+
+	ctx             context.Context
+	datanodes       []*hdds.DatanodeDetailsProto
+	currentDatanode hdds.DatanodeDetailsProto
+	grpcConnection  *grpc.ClientConn
+	pipelineId      *hdds.PipelineID
+	memberIndex     int
+}
+
+func (dn *DatanodeClient) GetCurrentDnUUid() *string {
+	uid := dn.currentDatanode.GetUuid()
+	return &uid
+}
+
+func (dnClient *DatanodeClient) connectToNext() error {
+	if dnClient.grpcConnection != nil {
+		dnClient.grpcConnection.Close()
+	}
+	dnClient.memberIndex = dnClient.memberIndex + 1
+	if dnClient.memberIndex == len(dnClient.datanodes) {
+		dnClient.memberIndex = 0
+	}
+	selectedDatanode := dnClient.datanodes[dnClient.memberIndex]
+	dnClient.currentDatanode = *selectedDatanode
+
+	standalonePort := 0
+	for _, port := range dnClient.currentDatanode.Ports {
+		if *port.Name == "STANDALONE" {
+			standalonePort = int(*port.Value)
+		}
+	}
+
+	address := *dnClient.currentDatanode.IpAddress + ":" + strconv.Itoa(standalonePort)
+	println("Connecting to the " + address)
+	conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
+	if err != nil {
+		return err
+	}
+
+	dnClient.ratisReceiver = make(chan ratis.RaftClientReplyProto)
+	dnClient.standaloneReceiver = make(chan dnapi.ContainerCommandResponseProto)
+
+	client, err := dnapi.NewXceiverClientProtocolServiceClient(conn).Send(dnClient.ctx)
+	dnClient.standaloneClient = &client
+	//
+	//client, err := ratis.NewRaftClientProtocolServiceClient(conn).Unordered(dnClient.ctx)
+	//if err != nil {
+	//	panic(err)
+	//}
+	//dnClient.ratisClient = &client
+	//go dnClient.RaftReceiver()

Review comment:
       Sure, it can definitely be removed. I am pushing the fix.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org