data_node.go 1.8 KB
Newer Older
C
cai.zhang 已提交
1 2 3 4 5 6 7 8 9 10 11
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// 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.

X
XuanYang-cn 已提交
12 13 14 15 16
package components

import (
	"context"

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

X
Xiangyu Wang 已提交
19 20 21
	grpcdatanode "github.com/milvus-io/milvus/internal/distributed/datanode"
	"github.com/milvus-io/milvus/internal/log"
	"github.com/milvus-io/milvus/internal/msgstream"
X
XuanYang-cn 已提交
22 23
)

24
// DataNode implements DataNode grpc server
X
XuanYang-cn 已提交
25 26
type DataNode struct {
	ctx context.Context
27
	svr *grpcdatanode.Server
X
XuanYang-cn 已提交
28 29
}

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

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

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

52
// Stop terminates service
X
XuanYang-cn 已提交
53
func (d *DataNode) Stop() error {
54 55 56 57
	if err := d.svr.Stop(); err != nil {
		return err
	}
	return nil
X
XuanYang-cn 已提交
58
}
D
dragondriver 已提交
59

60
// GetComponentStates returns DataNode's states
D
dragondriver 已提交
61 62 63
func (d *DataNode) GetComponentStates(ctx context.Context, request *internalpb.GetComponentStatesRequest) (*internalpb.ComponentStates, error) {
	return d.svr.GetComponentStates(ctx, request)
}