data_node.go 1.7 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 25
)

type DataNode struct {
	ctx context.Context
26
	svr *grpcdatanode.Server
X
XuanYang-cn 已提交
27 28
}

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

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

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

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

func (d *DataNode) GetComponentStates(ctx context.Context, request *internalpb.GetComponentStatesRequest) (*internalpb.ComponentStates, error) {
	return d.svr.GetComponentStates(ctx, request)
}