system-pharos-node-go

module
v0.0.0-...-ed2735e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2020 License: Apache-2.0

README

System Management - Pharos Node

This is intented to be installed in each of Edge devices, which communicates with centralized service deployment management, called Pharos Anchor, running in a management server. Once Pharos Anchor sends a request of service deployment to a certain Edge device, the corresponding Pharos Node performs one of Docker operations to pull, run, and stop containers as requested.

Build Prerequisites

How to build

This provides how to build sources codes to an excutable binary and dockerize it to create a Docker image.

1. Executable binary
$ ./build.sh

If source codes are successfully built, you can find an output binary file, main, on a root of project folder. Note that, you can find other build scripts, build_arm.sh and build_arm64, which can be used to build the codes for ARM and ARM64 machines, respectively.

2. Docker Image

Next, you can create it to a Docker image.

$ docker build -t system-pharos-node-go-ubuntu -f Dockerfile .

If it succeeds, you can see the built image as follows:

$ sudo docker images
REPOSITORY                         TAG        IMAGE ID        CREATED           SIZE
system-pharos-node-go-ubuntu       latest     fcbbd4c401c2    31 seconds ago    157MB

Note that, you can find other Dockerfiles, Dockerfile_arm and Dockerfile_arm64, which can be used to dockerize for ARM and ARM64 machines, respectively.

How to run with Docker image

Required options to run Docker image

  • port
    • 48098:48098
  • environment variables
    • [Mandatory] ANCHOR_ADDRESS='...'
    • [Mandatory] NODE_ADDRESS='...'
    • [Optional] REVERSE_PROXY=true/false
    • [Optional] ANCHOR_REVERSE_PROXY=true/false
    • [Optional] DEVICE_ID='...'
    • [Optional] DEVICE_NAME='...'
  • volume
    • "host folder"/data/db:/data/db (Note that you should replace "host folder" to a desired folder on your host machine)

You can execute it with a Docker image as follows:

$ docker run -it \
	-p 48098:48098 \
	-e ANCHOR_ADDRESS='...' \
	-e NODE_ADDRESS='...' \
	-e REVERSE_PROXY='true/false' \
	-e ANCHOR_REVERSE_PROXY='true/false' \
	-e DEVICE_ID='...' \
	-e DEVICE_NAME='...' \
	-v /data/db:/data/db \
	-v /var/run/docker.sock:/var/run/docker.sock \
	system-pharos-node-go-ubuntu

If it succeeds, you can see log messages on your screen as follows:

$ docker run -it -p 48088:48098 -e ANCHOR_ADDRESS={IP} -e NODE_ADDRESS={IP} -v /pharos-node/data/db:/data/db -v /var/run/docker.sock:/var/run/docker.sock system-pharos-node-go-ubuntu
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 135 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 140 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 135 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 140 [OUT]
[ERROR][NODE]2018/07/04 07:38:40 controller/configuration configuration.go getProxyInfo : 216 [No reverse proxy environment]
[ERROR][NODE]2018/07/04 07:38:40 controller/configuration configuration.go initConfiguration : 109 [unknown error : No reverse proxy environment]
[DEBUG][NODE]2018/07/04 07:38:40 controller/dockercontroller.dockerExecutorImpl dockerexecutor.go Info : 151 []
[DEBUG][NODE]2018/07/04 07:38:40 controller/dockercontroller.dockerExecutorImpl dockerexecutor.go Info : 173 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 135 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 140 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 113 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/deployment deploymentcontroller.go restoreAllAppsState : 986 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/service.Executor service.go GetAppList : 155 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/service.Executor service.go GetAppList : 171 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/deployment deploymentcontroller.go restoreAllAppsState : 1014 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health registration.go register : 96 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 controller/configuration.Executor configuration.go GetConfiguration : 148 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperties : 155 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperties : 171 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/configuration.Executor configuration.go GetConfiguration : 168 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/service.Executor service.go GetAppList : 155 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/service.Executor service.go GetAppList : 171 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health registration.go sendRegisterRequest : 182 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go MakeAnchorRequestUrl : 102 [http://{IP}:48099/api/v1/management/nodes/register]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertMapToJson : 56 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertMapToJson : 63 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health registration.go sendRegisterRequest : 195 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertJsonToMap : 41 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertJsonToMap : 49 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 135 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 148 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 89 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go SetProperty : 128 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go startHealthCheck : 31 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 controller/configuration.Executor configuration.go GetConfiguration : 148 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperties : 155 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperties : 171 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/configuration.Executor configuration.go GetConfiguration : 168 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go startHealthCheck : 73 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health registration.go register : 150 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 main main.go main : 25 [Start Pharos Node]
[DEBUG][NODE]2018/07/04 07:38:40 api restapi.go RunNodeWebServer : 39 [Start Pharos Node Web Server]
[DEBUG][NODE]2018/07/04 07:38:40 api restapi.go RunNodeWebServer : 40 [Listening 0.0.0.0:48098]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go sendPingRequest : 81 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 135 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 db/bolt/configuration.Executor configuration.go GetProperty : 148 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertMapToJson : 56 [IN]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go ConvertMapToJson : 63 [OUT]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go sendPingRequest : 100 [try to send ping request]
[DEBUG][NODE]2018/07/04 07:38:40 commons/util util.go MakeAnchorRequestUrl : 102 [http://{IP}:48099/api/v1/management/nodes/4bd8554a-c9d2-4b06-82d9-c4231fb326af/ping]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go sendPingRequest : 114 [receive pong response, code[200]]
[DEBUG][NODE]2018/07/04 07:38:40 controller/health checks.go sendPingRequest : 115 [OUT]

(Optional) How to enable QEMU environment on your computer

QEMU could be useful if you want to test your implemetation on various CPU architectures(e.g. ARM, ARM64) but you have only Ubuntu PC. To enable QEMU on your machine, please do as follows.

Required packages for QEMU:

$ apt-get install -y qemu-user-static binfmt-support

For ARM 32bit:

$ echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register <br />

For ARM 64bit:

$ echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-static:' > /proc/sys/fs/binfmt_misc/register <br />

Now, you can build your implementation and dockerize it for ARM and ARM64 on your Ubuntu PC. The below is an example for ARM build.

$ ./build_arm.sh
$ docker build -t system-pharos-node-go-arm -f Dockerfile_arm .

Directories

Path Synopsis
src
api
******************************************************************************
******************************************************************************
api/common
******************************************************************************
******************************************************************************
api/configuration
******************************************************************************
******************************************************************************
api/configuration/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
api/deployment
******************************************************************************
******************************************************************************
api/device
******************************************************************************
******************************************************************************
api/device/mocks
Package mock_device is a generated GoMock package.
Package mock_device is a generated GoMock package.
api/health
******************************************************************************
******************************************************************************
api/monitoring/resource
******************************************************************************
******************************************************************************
api/notification/apps
******************************************************************************
******************************************************************************
api/notification/apps/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
api/notification/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
commons/errors
Package commons/errors defines error cases of Pharos Node.
Package commons/errors defines error cases of Pharos Node.
commons/logger
Package commons/logger implements log stream which is used on Pharos Node.
Package commons/logger implements log stream which is used on Pharos Node.
commons/url
Package commons/url defines url used by Pharos Node.
Package commons/url defines url used by Pharos Node.
commons/util
Package commons/util defines utility functions used by Pharos Node.
Package commons/util defines utility functions used by Pharos Node.
controller/configuration
Package configuration provide virtual functionality of configuration.
Package configuration provide virtual functionality of configuration.
controller/deployment
Package controller provides controllability of persistence database and docker(docker-compose).
Package controller provides controllability of persistence database and docker(docker-compose).
controller/deployment/mocks
Package mock_deployment is a generated GoMock package.
Package mock_deployment is a generated GoMock package.
controller/device
******************************************************************************
******************************************************************************
controller/device/mocks
Package mock_device is a generated GoMock package.
Package mock_device is a generated GoMock package.
controller/dockercontroller
******************************************************************************
******************************************************************************
controller/dockercontroller/mocks
Package mock_dockercontroller is a generated GoMock package.
Package mock_dockercontroller is a generated GoMock package.
controller/health
Package health provides logic of checking health with system-edge-manager service.
Package health provides logic of checking health with system-edge-manager service.
controller/health/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
controller/monitoring/apps
******************************************************************************
******************************************************************************
controller/monitoring/apps/mocks
Package mock_apps is a generated GoMock package.
Package mock_apps is a generated GoMock package.
controller/monitoring/resource
******************************************************************************
******************************************************************************
controller/monitoring/resource/mocks
Package mock_resource is a generated GoMock package.
Package mock_resource is a generated GoMock package.
controller/notification/apps
******************************************************************************
******************************************************************************
controller/notification/apps/mocks
Package mock_apps is a generated GoMock package.
Package mock_apps is a generated GoMock package.
controller/shellcommand
Package shellcommand provide functionlity of command to shell.
Package shellcommand provide functionlity of command to shell.
db/bolt/configuration/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
db/bolt/event/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
db/bolt/service/mocks
Package mock_service is a generated GoMock package.
Package mock_service is a generated GoMock package.
db/bolt/wrapper
******************************************************************************
******************************************************************************
db/bolt/wrapper/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
main
******************************************************************************
******************************************************************************
messenger/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL