data_node.go 1.9 KB
Newer Older
1 2 3 4 5 6
// Licensed to the LF AI & Data foundation 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
C
cai.zhang 已提交
7 8
// with the License. You may obtain a copy of the License at
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
C
cai.zhang 已提交
10
//
11 12 13 14 15
// 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.
C
cai.zhang 已提交
16

X
XuanYang-cn 已提交
17 18 19 20 21
package components

import (
	"context"

D
dragondriver 已提交
22 23
	"github.com/milvus-io/milvus/internal/proto/internalpb"

X
Xiangyu Wang 已提交
24 25
	grpcdatanode "github.com/milvus-io/milvus/internal/distributed/datanode"
	"github.com/milvus-io/milvus/internal/log"
J
jaime 已提交
26
	"github.com/milvus-io/milvus/internal/mq/msgstream"
X
XuanYang-cn 已提交
27 28
)

29
// DataNode implements DataNode grpc server
X
XuanYang-cn 已提交
30 31
type DataNode struct {
	ctx context.Context
32
	svr *grpcdatanode.Server
X
XuanYang-cn 已提交
33 34
}

35
// NewDataNode creates a new DataNode
G
groot 已提交
36
func NewDataNode(ctx context.Context, factory msgstream.Factory) (*DataNode, error) {
37
	svr, err := grpcdatanode.NewServer(ctx, factory)
X
XuanYang-cn 已提交
38
	if err != nil {
39
		return nil, err
X
XuanYang-cn 已提交
40 41 42 43 44 45 46 47
	}

	return &DataNode{
		ctx: ctx,
		svr: svr,
	}, nil
}

48
// Run starts service
X
XuanYang-cn 已提交
49
func (d *DataNode) Run() error {
50
	if err := d.svr.Run(); err != nil {
X
XuanYang-cn 已提交
51 52
		panic(err)
	}
X
XuanYang-cn 已提交
53
	log.Debug("Datanode successfully started")
X
XuanYang-cn 已提交
54 55 56
	return nil
}

57
// Stop terminates service
X
XuanYang-cn 已提交
58
func (d *DataNode) Stop() error {
59 60 61 62
	if err := d.svr.Stop(); err != nil {
		return err
	}
	return nil
X
XuanYang-cn 已提交
63
}
D
dragondriver 已提交
64

65
// GetComponentStates returns DataNode's states
D
dragondriver 已提交
66 67 68
func (d *DataNode) GetComponentStates(ctx context.Context, request *internalpb.GetComponentStatesRequest) (*internalpb.ComponentStates, error) {
	return d.svr.GetComponentStates(ctx, request)
}