repository structuring
authorwansuyoo <wansu.yoo@samsung.com>
Thu, 28 Mar 2019 05:32:31 +0000 (14:32 +0900)
committerwansuyoo <wansu.yoo@samsung.com>
Thu, 28 Mar 2019 05:32:31 +0000 (14:32 +0900)
.gitignore
Makefile [new file with mode: 0644]
build.sh
coverage.sh [deleted file]
register_service.sh [deleted file]
src/interface/main.go [new file with mode: 0644]
src/interface/types.go [new file with mode: 0644]
src/main-c/orchestration.h [new file with mode: 0644]

index ebc62b8..2965f15 100644 (file)
@@ -14,3 +14,4 @@ doc/generate-api/*
 
 # Output of the go coverage tool, specifically when used with LiteIDE
 *.out
+*.html
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..6231962
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,59 @@
+# Go parameters
+GOCMD       := go
+GOBUILD     := $(GOCMD) build
+GOCLEAN     := $(GOCMD) clean
+GOLINT         := golint
+GOVET          := $(GOCMD) vet
+GOCOVER     := gocov
+GO_LDFLAGS  := -ldflags '-extldflags "-static"'
+
+# Target parameters
+BINARY_FILE    := edge-orchestration
+OBJECT_FILE            := orchestration.so
+HEADER_FILE            := orchestration.h
+EXEC_SRC_DIR    := orchestration
+OBJ_SRC_DIR            := interface
+BIN_DIR        := $(BASE_DIR)/bin
+CMAIN_DIR              := $(BASE_DIR)/src/main-c
+PKG_DIRS               := servicemgr devicemgr restapi/v1
+
+.DEFAULT_GOAL := help
+
+## test and build
+all: build
+
+## edge-orchestration binary build
+build-binary:
+       $(GOBUILD) -a $(GO_LDFLAGS) -o $(BIN_DIR)/$(BINARY_FILE) $(EXEC_SRC_DIR) || exit 1
+       ls -al $(BIN_DIR)
+
+## edge-orchestration shared object build
+build-object:
+       CGO_ENABLED=1 $(GOBUILD) -o $(BIN_DIR)/$(OBJECT_FILE) -buildmode=c-shared -linkshared $(OBJ_SRC_DIR) || exit 1
+       ls -al $(BIN_DIR)
+       cp $(BIN_DIR)/$(OBJECT_FILE) $(CMAIN_DIR)
+       cp $(BIN_DIR)/$(HEADER_FILE) $(CMAIN_DIR)
+
+## go test and coverage
+test:
+       $(GOCOVER) test $(PKG_DIRS) > coverage.out
+       $(GOCOVER) report coverage.out
+       $(GOCOVER)-html coverage.out > coverage.html
+       firefox coverage.html &
+
+## build clean
+clean:
+       $(GOCLEAN)
+       rm -f $(BIN_DIR)/*
+
+## check go style and static analysis
+lint:
+       $(GOLINT) ./src/...
+       $(GOVET) ./src/...
+
+## show help
+help:
+       @make2help $(MAKEFILE_LIST)
+
+## define build target not a file
+.PHONY: all build test clean lint help
\ No newline at end of file
index f4f878b..447d2df 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,16 +1,83 @@
 #! /bin/bash
-SERVICE_BIN="edge-orchestration"
-BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
 
-if [ -e $BASE_DIR/vendor/ ]; then
-    ln -sf $BASE_DIR/vendor $BASE_DIR/vendor/src
-fi
+export BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
+
+BINARY_FILE="edge-orchestration"
+SERVICE_DIR="/etc/systemd/system"
+SERVICE_FILE="edge-orchestration.service"
+
+BUILD_ALL=false
 
+echo "*****************************"
+echo " Target Binary arch is amd64 "
+echo "*****************************"
 export GOARCH=amd64
-export GOBIN=$BASE_DIR/bin
 export GOPATH=$GOPATH:$BASE_DIR:$BASE_DIR/vendor
 
-go build -a -ldflags '-extldflags "-static"' -o $BASE_DIR/bin/$SERVICE_BIN orchestration
+if [ "$1" = "all" ]; then
+    BUILD_ALL=true
+fi
+
+
+function install_prerequisite() {
+    go get github.com/axw/gocov/gocov
+    go get github.com/matm/gocov-html
+    go get github.com/Songmu/make2help/cmd/make2help
+}
+
+function build_clean() {
+    make clean
+}
+
+function build_binary() {
+    make build-binary
+}
+
+function build_object() {
+    make build-object
+}
+
+function build_test() {
+    make test
+}
+
+function lint_src_code() {
+    make lint
+}
+
+function register_service() {
+    echo ""
+    echo "-----------------------------------"
+    echo "  Create Service File [SuperUser]"
+    echo "-----------------------------------"
+
+    sudo systemctl stop $SERVICE_FILE
+    sudo cp $BASE_DIR/bin/$BINARY_FILE /usr/bin
+    sudo cp $BASE_DIR/packaging/$SERVICE_FILE $SERVICE_DIR
+    ls -al $SERVICE_DIR | grep $SERVICE_FILE
+
+    echo ""
+    echo "----------------------------------------"
+    echo "  Register Edge-Orchestration Service"
+    echo "----------------------------------------"
+
+    sudo systemctl daemon-reload
+    sudo systemctl restart $SERVICE_FILE
+    sudo systemctl status $SERVICE_FILE
+}
+
+
+if [ "$BUILD_ALL" = true ]
+then
+    install_prerequisite
+    build_clean
+    build_test
+    build_binary
+    build_object
+    lint_src_code
+       register_service
+else
+    build_clean
+    build_binary
+fi
 
-cd $GOBIN
-ls -ail
\ No newline at end of file
diff --git a/coverage.sh b/coverage.sh
deleted file mode 100755 (executable)
index a4bae01..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /bin/bash
-
-export GOPATH=$GOPATH:$BASE_DIR:$BASE_DIR/vendor
-
-go test -v -cover restapi/v1 -coverpkg=servicemgr,devicemgr,restapi -coverprofile cover.out
-go tool cover -html=cover.out -o cover.html
-
-firefox cover.html
\ No newline at end of file
diff --git a/register_service.sh b/register_service.sh
deleted file mode 100755 (executable)
index 8117826..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#! /bin/bash
-
-SERVICE_DIR="/etc/systemd/system"
-SERVICE_FILE="edge-orchestration.service"
-SERVICE_BIN="edge-orchestration"
-
-echo "-------------------------------------"
-echo "  Create Edge-Orchestration Binary"
-echo "-------------------------------------"
-
-BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
-# ZMQ_VERSION="zmq_4_x"s
-
-export GOARCH=amd64
-export GOPATH=$GOPATH:$BASE_DIR:$BASE_DIR/vendor
-
-# go build -tags $ZMQ_VERSION -a -o $BASE_DIR/bin/$SERVICE_BIN orchestration || exit 1
-go build -a -ldflags '-extldflags "-static"' -o $BASE_DIR/bin/$SERVICE_BIN orchestration
-
-ls -al $BASE_DIR/bin
-
-echo ""
-echo "-----------------------------------"
-echo "  Create Service File [SuperUser]"
-echo "-----------------------------------"
-
-sudo systemctl stop $SERVICE_FILE
-sudo cp $BASE_DIR/bin/$SERVICE_BIN /usr/bin
-sudo cp $BASE_DIR/packaging/$SERVICE_FILE $SERVICE_DIR
-ls -al $SERVICE_DIR | grep $SERVICE_FILE
-
-echo ""
-echo "----------------------------------------"
-echo "  Register Edge-Orchestration Service"
-echo "----------------------------------------"
-
-sudo systemctl daemon-reload
-sudo systemctl restart $SERVICE_FILE
-sudo systemctl status $SERVICE_FILE
diff --git a/src/interface/main.go b/src/interface/main.go
new file mode 100644 (file)
index 0000000..97c1190
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Edge Orchestration
+ *
+ * Edge Orchestration support to deliver distributed service process environment.
+ *
+ * API version: v1-20190307
+ * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
+ */
+
+package main
+
+import "C"
+
+import (
+       "log"
+)
+
+//export OrchestrationInit
+func OrchestrationInit() (errCode C.int) {
+       log.Printf("[%s] OrchestrationInit", logPrefix)
+       errCode = 0
+
+       return
+}
+
+//export OrchestrationRequestService
+func OrchestrationRequestService() (errCode C.int) {
+       log.Printf("[%s] OrchestrationRequestService", logPrefix)
+       errCode = 0
+
+       return
+}
+
+func main() {}
diff --git a/src/interface/types.go b/src/interface/types.go
new file mode 100644 (file)
index 0000000..4b6c8c0
--- /dev/null
@@ -0,0 +1,3 @@
+package main
+
+var logPrefix = "liborchestration"
diff --git a/src/main-c/orchestration.h b/src/main-c/orchestration.h
new file mode 100644 (file)
index 0000000..50bfb22
--- /dev/null
@@ -0,0 +1,74 @@
+/* Code generated by cmd/cgo; DO NOT EDIT. */
+
+/* package interface */
+
+
+#line 1 "cgo-builtin-prolog"
+
+#include <stddef.h> /* for ptrdiff_t below */
+
+#ifndef GO_CGO_EXPORT_PROLOGUE_H
+#define GO_CGO_EXPORT_PROLOGUE_H
+
+typedef struct { const char *p; ptrdiff_t n; } _GoString_;
+
+#endif
+
+/* Start of preamble from import "C" comments.  */
+
+
+
+
+/* End of preamble from import "C" comments.  */
+
+
+/* Start of boilerplate cgo prologue.  */
+#line 1 "cgo-gcc-export-header-prolog"
+
+#ifndef GO_CGO_PROLOGUE_H
+#define GO_CGO_PROLOGUE_H
+
+typedef signed char GoInt8;
+typedef unsigned char GoUint8;
+typedef short GoInt16;
+typedef unsigned short GoUint16;
+typedef int GoInt32;
+typedef unsigned int GoUint32;
+typedef long long GoInt64;
+typedef unsigned long long GoUint64;
+typedef GoInt64 GoInt;
+typedef GoUint64 GoUint;
+typedef __SIZE_TYPE__ GoUintptr;
+typedef float GoFloat32;
+typedef double GoFloat64;
+typedef float _Complex GoComplex64;
+typedef double _Complex GoComplex128;
+
+/*
+  static assertion to make sure the file is being used on architecture
+  at least with matching size of GoInt.
+*/
+typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
+
+typedef _GoString_ GoString;
+typedef void *GoMap;
+typedef void *GoChan;
+typedef struct { void *t; void *v; } GoInterface;
+typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
+
+#endif
+
+/* End of boilerplate cgo prologue.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern int OrchestrationInit();
+
+extern int OrchestrationRequestService();
+
+#ifdef __cplusplus
+}
+#endif