Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customized mapper #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ help:
#
# Usage:
# make template : create a mapper based on a template.
# make dmitemplate : create a mapper-dmi based on a template.
# make mapper {mapper-name} <action> <parameter>: execute mapper building process.
# make device {device-name} <action> <parameter>: execute device simulator build process. (only used by modbus)
# make e2e {mapper-name} : execute mapper e2e building process. (only support modbus and opcua)
Expand Down Expand Up @@ -36,4 +37,4 @@ $(make_rules):
@$(curr_dir)/hack/make-rules/[email protected] $(rest_args)

.DEFAULT_GOAL := all
.PHONY: $(make_rules) build
.PHONY: $(make_rules) build
10 changes: 10 additions & 0 deletions _template/mapper-dmi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:16.04

RUN mkdir -p kubeedge

COPY ./bin/Template kubeedge/
COPY ./config.yaml kubeedge/

WORKDIR kubeedge

CMD ./Template
36 changes: 36 additions & 0 deletions _template/mapper-dmi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
SHELL := /bin/bash

curr_dir := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
rest_args := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))
$(eval $(rest_args):;@:)

help:
#
# Usage:
# make template : create a mapper based on a template.
# make mapper {mapper-name} <action> <parameter>: execute mapper building process.
# make all : execute building process to all mappers.
#
# Actions:
# - mod, m : download code dependencies.
# - lint, l : verify code via go fmt and `golangci-lint`.
# - build, b : compile code.
# - package, p : package docker image.
# - test, t : run unit tests.
# - clean, c : clean output binary.
#
# Parameters:
# ARM : true or undefined
# ARM64 : true or undefined
#
# Example:
# - make mapper modbus ARM64=true : execute `build` "modbus" mapper for ARM64.
# - make mapper modbus test : execute `test` "modbus" mapper.
@echo

make_rules := $(shell ls $(curr_dir)/hack/make-rules | sed 's/.sh//g')
$(make_rules):
@$(curr_dir)/hack/make-rules/[email protected] $(rest_args)

.DEFAULT_GOAL := help
.PHONY: $(make_rules) build test package
63 changes: 63 additions & 0 deletions _template/mapper-dmi/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"errors"
"os"

"k8s.io/klog/v2"

"github.com/kubeedge/mappers-go/config"
"github.com/kubeedge/mappers-go/mappers/Template/device"
"github.com/kubeedge/mappers-go/pkg/common"
"github.com/kubeedge/mappers-go/pkg/grpcserver"
"github.com/kubeedge/mappers-go/pkg/util/grpcclient"
"github.com/kubeedge/mappers-go/pkg/util/parse"
)

func main() {
var err error
var c config.Config

klog.InitFlags(nil)
defer klog.Flush()

if err = c.Parse(); err != nil {
klog.Fatal(err)
os.Exit(1)
}
klog.Infof("config: %+v", c)

grpcclient.Init(&c)

// start grpc server
grpcServer := grpcserver.NewServer(
grpcserver.Config{
SockPath: c.GrpcServer.SocketPath,
Protocol: common.ProtocolCustomized,
},
device.NewDevPanel(),
)

panel := device.NewDevPanel()
err = panel.DevInit(&c)
if err != nil && !errors.Is(err, parse.ErrEmptyData) {
klog.Fatal(err)
}
klog.Infoln("devInit finished")

// register to edgecore
// if dev init mode is register, mapper's dev will init when registry to edgecore
if c.DevInit.Mode != common.DevInitModeRegister {
klog.Infoln("======dev init mode is not register, will register to edgecore")
// TODO health check
if _, _, err = grpcclient.RegisterMapper(&c, false); err != nil {
klog.Fatal(err)
}
klog.Infoln("registerMapper finished")
}
go panel.DevStart()
defer grpcServer.Stop()
if err = grpcServer.Start(); err != nil {
klog.Fatal(err)
}
}
12 changes: 12 additions & 0 deletions _template/mapper-dmi/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
grpc_server:
socket_path: /etc/kubeedge/Template.sock
common:
name: Template-mapper
version: v1.13.0
api_version: v1.0.0
protocol: # TODO your protocol name
address: 127.0.0.1
edgecore_sock: /etc/kubeedge/dmi.sock
dev_init:
mode: register

Loading