Skip to content

Commit

Permalink
Add initialization of the file system for the orchestrator (lf-edge#318)
Browse files Browse the repository at this point in the history
Signed-off-by: Taras Drozdovskyi <t.drozdovsky@samsung.com>

- If the file system required to work of edge-orchestration is not yet created, then it creates file system.
- This commit is for resolving the above painpoint by adding the initiation of the file system for the orchestrator.
  • Loading branch information
tdrozdovsky authored Jun 23, 2021
1 parent 9c3b146 commit 3722c32
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 41 deletions.
7 changes: 0 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ function build_docker_container() {
}

function run_docker_container() {
### Add temporarily, TO DO: move files into container
echo ""
echo "--------------------------------------------"
echo " Create prerequisite Folder [SuperUser]"
echo "--------------------------------------------"
sudo ./tools/create_fs.sh
echo ""
echo "**********************************"
echo " Run Docker container "
echo "**********************************"
Expand Down
6 changes: 6 additions & 0 deletions cmd/edge-orchestration/capi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import (
"sync"
"unsafe"

"github.com/lf-edge/edge-home-orchestration-go/internal/common/fscreator"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/storagemgr"

Expand Down Expand Up @@ -152,6 +153,11 @@ func OrchestrationInit() C.int {
log.Println(">>> buildTags : ", buildTags)
wrapper.SetBoltDBPath(dbPath)

if err := fscreator.CreateFileSystem(edgeDir); err != nil {
log.Panicf("%s Failed to create edge-orchestration file system\n", logPrefix)
return -1
}

isSecured := false
if strings.Contains(buildTags, "secure") {
log.Println("Orchestration init with secure option")
Expand Down
7 changes: 7 additions & 0 deletions cmd/edge-orchestration/javaapi/javaapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sync"
"time"

"github.com/lf-edge/edge-home-orchestration-go/internal/common/fscreator"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/networkhelper"

Expand Down Expand Up @@ -65,6 +66,7 @@ const (

cipherKeyFile = "/user/orchestration_userID.txt"
deviceIDFile = "/device/orchestration_deviceID.txt"

)

var (
Expand Down Expand Up @@ -165,6 +167,11 @@ type ExecuteCallback interface {
func OrchestrationInit(executeCallback ExecuteCallback, edgeDir string, isSecured bool) (errCode int) {
initPlatformPath(edgeDir)

if err := fscreator.CreateFileSystem(edgeDir); err != nil {
log.Panicf("%s Failed to create edge-orchestration file system\n", logPrefix)
return
}

logmgr.InitLogfile(logPath)
log.Printf("[%s] OrchestrationInit", logPrefix)

Expand Down
6 changes: 6 additions & 0 deletions cmd/edge-orchestration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"strings"

"github.com/lf-edge/edge-home-orchestration-go/internal/common/fscreator"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/sigmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/storagemgr"
Expand Down Expand Up @@ -94,6 +95,11 @@ func orchestrationInit() error {
log.Println(">>> buildTags : ", buildTags)
wrapper.SetBoltDBPath(dbPath)

if err := fscreator.CreateFileSystem(edgeDir); err != nil {
log.Panicf("%s Failed to create edge-orchestration file system\n", logPrefix)
return err
}

secure := os.Getenv("SECURE")
mnedc := os.Getenv("MNEDC")

Expand Down
15 changes: 3 additions & 12 deletions docs/platforms/x86_64_linux/x86_64_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,16 @@ test
   ├── copy_srvs.sh
    └── ls_srv
    └── ls_srv.conf
tools
└── create_fs.sh
```

1. To start for the first time, need to create a file system (only once need to execute the command)
```
$ cd tools
$ sudo ./create_fs.sh
```

2. Copy the folder with the service configuration file from `services` to `/var/edge-orchestration/apps` or use `copy_srvs.sh` to copy all service folders to `/var/edge-orchestration/apps`.
1. Copy the folder with the service configuration file from `services` to `/var/edge-orchestration/apps` or use `copy_srvs.sh` to copy all service folders to `/var/edge-orchestration/apps`.
```
$ cd test/native
$ sudo ./copy_srvs.sh
```
> The structure of the [configuration file](../../../internal/controller/configuremgr/native/description/doc.go) and example can be found [ls_srv.conf](../../../test/native/ls_srv/ls_srv.conf).
3. To build the native edge-orchestration, run the following commands:
2. To build the native edge-orchestration, run the following commands:
```
$ cd examples/native
$ make
Expand All @@ -71,7 +62,7 @@ gcc -c -I../../bin/capi/output/inc/linux_x86-64 main.c -o main.o
gcc main.o -L../../bin/capi/output/lib/linux_x86-64 -pthread -lorchestration -o edge-orchestration
```
4. Run native edge-orchestration
3. Run native edge-orchestration
```
$ sudo ./edge-orchestration
2020/07/20 09:24:10 main.go:158: [interface] OrchestrationInit
Expand Down
65 changes: 65 additions & 0 deletions internal/common/fscreator/fscreator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright 2021 Samsung Electronics 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.
*
*******************************************************************************/

package fscreator

import (
"os"

"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
)

const (
logPrefix = "[fscreator]"
)

var edgeDirs = []string{
"/apps",
"/data/db",
"/data/cert",
"/datastorage",
"/device",
"/log",
"/mnedc",
"/user",
}

var (
log = logmgr.GetInstance()
)

// CreateFileSystem creates a file system necessary for the work of the edge-orchestration
// ├── var
// └── edge-orchestration
// ├── apps
// ├── data
// │ ├── cert
// │ └── db
// ├── datastorage
// ├── device
// ├── log
// ├── mnedc
// └── user
func CreateFileSystem(edgeDir string) error {
for _, dir := range edgeDirs {
if err := os.MkdirAll(edgeDir+dir, os.ModePerm); err != nil {
log.Panicf("%s Failed to create %s: %s\n", logPrefix, edgeDir+dir, err)
return err
}
}
return nil
}
57 changes: 57 additions & 0 deletions internal/common/fscreator/fscreator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright 2021 Samsung Electronics 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.
*
*******************************************************************************/

package fscreator

import (
"os"
"testing"
)

const (
fakefsPath = "fakefs"
unexpectedSuccess = "unexpected success"
unexpectedFail = "unexpected fail"
)

func TestCreateFileSystem(t *testing.T) {
t.Run("Success", func(t *testing.T) {
defer os.RemoveAll(fakefsPath)

CreateFileSystem(fakefsPath)
for _, dir := range edgeDirs {
if _, err := os.Stat(fakefsPath+dir); err != nil {
t.Error(err.Error())
}
}
})

t.Run("Error", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error(r)
}
for _, dir := range edgeDirs {
if _, err := os.Stat("/"+fakefsPath+dir); err == nil {
t.Error(unexpectedSuccess)
}
}
os.RemoveAll("/"+fakefsPath)
}()
CreateFileSystem("/"+fakefsPath)
})
}
22 changes: 0 additions & 22 deletions tools/create_fs.sh

This file was deleted.

0 comments on commit 3722c32

Please sign in to comment.