renamming sample component + fix logging

This commit is contained in:
abhiguptacse 2024-09-27 08:46:14 +00:00
Родитель 923fd740a6
Коммит 9db4ad5ebd
5 изменённых файлов: 179 добавлений и 178 удалений

Просмотреть файл

@ -8,13 +8,13 @@ logging:
components:
- libfuse
- block_cache
- test1
- test2
- sample_custom_component1
- sample_custom_component2
test1:
sample_custom_component1:
block-size-mb: 16
test2:
sample_custom_component2:
block-size-mb: 16
libfuse:
attribute-expiration-sec: 120

Просмотреть файл

@ -32,7 +32,7 @@ func init() {
} else {
files, err := os.ReadDir(pluginDirPath)
if err != nil {
log.Err("custom_loader::Error reading plugin directory:", err)
log.Err("custom_loader::Error reading plugin directory: %s", err.Error())
return
}
for _, file := range files {
@ -43,16 +43,17 @@ func init() {
}
for _, file := range pluginFiles {
log.Info("custom_loader::Opening plugin:", file)
log.Info("custom_loader::Opening plugin: %s", file)
p, err := plugin.Open(file)
if err != nil {
log.Err("custom_loader::Error opening plugin:", err.Error())
log.Err("custom_loader::Error opening plugin: %s", err.Error())
os.Exit(1)
}
log.Info("custom_loader::Plugin opened successfully")
getExternalComponentFunc, err := p.Lookup("GetExternalComponent")
if err != nil {
log.Err("custom_loader::Error looking up GetExternalComponent function:", err.Error())
log.Err("custom_loader::Error looking up GetExternalComponent function: %s", err.Error())
os.Exit(1)
}
getExternalComponent, ok := getExternalComponentFunc.(func() (string, func() external.Component))

Просмотреть файл

@ -1,142 +0,0 @@
package main
import (
"fmt"
"os"
"syscall"
"github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/external"
)
// SAMPLE EXTERNAL COMPONENT IMPLEMENTATION
// This is a sample external component implementation that can be used as a reference to implement external components.
// The external component should implement the external.Component interface.
const (
CompName = "test1"
Mb = 1024 * 1024
)
var _ external.Component = &test1{}
func (e *test1) SetName(name string) {
e.BaseComponent.SetName(name)
}
func (e *test1) SetNextComponent(nc external.Component) {
e.BaseComponent.SetNextComponent(nc)
}
func GetExternalComponent() (string, func() external.Component) {
return CompName, NewexternalComponent
}
func NewexternalComponent() external.Component {
comp := &test1{}
comp.SetName(CompName)
return comp
}
type test1 struct {
blockSize int64
external.BaseComponent
}
type test1Options struct {
BlockSize int64 `config:"block-size-mb" yaml:"block-size-mb,omitempty"`
}
func (e *test1) Configure(isParent bool) error {
log.Trace("test1::Configure")
conf := test1Options{}
err := config.UnmarshalKey(e.Name(), &conf)
if err != nil {
log.Err("test1::Configure : config error [invalid config attributes]")
return fmt.Errorf("error reading config for %s: %w", e.Name(), err)
}
if config.IsSet(e.Name()+".block-size-mb") && conf.BlockSize > 0 {
e.blockSize = conf.BlockSize * int64(Mb)
}
return nil
}
func (e *test1) CreateFile(opt external.CreateFileOptions) (*external.Handle, error) {
log.Trace("test1::CreateFile : %s", opt.Name)
handle, err := e.NextComponent().CreateFile(opt)
if err != nil {
log.Err("test1::CreateFile failed: %v", err)
return nil, err
}
return handle, nil
}
func (e *test1) CreateDir(opt external.CreateDirOptions) error {
log.Trace("test1::CreateDir : %s", opt.Name)
err := e.NextComponent().CreateDir(opt)
if err != nil {
log.Err("test1::CreateDir failed: %v", err)
return err
}
return nil
}
func (e *test1) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) {
log.Trace("test1::StreamDir : %s", options.Name)
attr, token, err := e.NextComponent().StreamDir(options)
if err != nil {
log.Err("test1::StreamDir failed: %v", err)
return nil, "", err
}
return attr, token, nil
}
func (e *test1) IsDirEmpty(options external.IsDirEmptyOptions) bool {
log.Trace("test2::IsDirEmpty : %s", options.Name)
empty := e.NextComponent().IsDirEmpty(options)
return empty
}
func (e *test1) DeleteDir(opt external.DeleteDirOptions) error {
log.Trace("test1::DeleteDir : %s", opt.Name)
err := e.NextComponent().DeleteDir(opt)
if err != nil {
log.Err("test1::DeleteDir failed: %v", err)
return err
}
return nil
}
func (e *test1) StageData(opt external.StageDataOptions) error {
log.Trace("test1::StageData : %s", opt.Name)
err := e.NextComponent().StageData(opt)
if err != nil {
log.Err("test1 StageData failed: %v", err)
return err
}
return nil
}
func (e *test1) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) {
log.Trace("test1::ReadInBuffer : %s", opt.Handle.Path)
n, err := e.NextComponent().ReadInBuffer(opt)
if err != nil {
log.Err("test1 ReadInBuffer failed: %v", err)
return 0, err
}
return n, nil
}
func (e *test1) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) {
log.Trace("test1::GetAttr : %s", options.Name)
attr, err = e.NextComponent().GetAttr(options)
if err != nil {
if os.IsNotExist(err) {
log.Trace("test1::GetAttr : File not found: %s", options.Name)
return nil, syscall.ENOENT
}
log.Err("test1 GetAttr failed: %v", err)
return nil, err
}
return attr, nil
}

Просмотреть файл

@ -0,0 +1,142 @@
package main
import (
"fmt"
"os"
"syscall"
"github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/external"
)
// SAMPLE EXTERNAL COMPONENT IMPLEMENTATION
// This is a sample external component implementation that can be used as a reference to implement external components.
// The external component should implement the external.Component interface.
const (
CompName = "sample_custom_component1"
Mb = 1024 * 1024
)
var _ external.Component = &sample_custom_component1{}
func (e *sample_custom_component1) SetName(name string) {
e.BaseComponent.SetName(name)
}
func (e *sample_custom_component1) SetNextComponent(nc external.Component) {
e.BaseComponent.SetNextComponent(nc)
}
func GetExternalComponent() (string, func() external.Component) {
return CompName, NewexternalComponent
}
func NewexternalComponent() external.Component {
comp := &sample_custom_component1{}
comp.SetName(CompName)
return comp
}
type sample_custom_component1 struct {
blockSize int64
external.BaseComponent
}
type sample_custom_component1Options struct {
BlockSize int64 `config:"block-size-mb" yaml:"block-size-mb,omitempty"`
}
func (e *sample_custom_component1) Configure(isParent bool) error {
log.Trace("sample_custom_component1::Configure")
conf := sample_custom_component1Options{}
err := config.UnmarshalKey(e.Name(), &conf)
if err != nil {
log.Err("sample_custom_component1::Configure : config error [invalid config attributes]")
return fmt.Errorf("error reading config for %s: %w", e.Name(), err)
}
if config.IsSet(e.Name()+".block-size-mb") && conf.BlockSize > 0 {
e.blockSize = conf.BlockSize * int64(Mb)
}
return nil
}
func (e *sample_custom_component1) CreateFile(opt external.CreateFileOptions) (*external.Handle, error) {
log.Trace("sample_custom_component1::CreateFile : %s", opt.Name)
handle, err := e.NextComponent().CreateFile(opt)
if err != nil {
log.Err("sample_custom_component1::CreateFile failed: %v", err)
return nil, err
}
return handle, nil
}
func (e *sample_custom_component1) CreateDir(opt external.CreateDirOptions) error {
log.Trace("sample_custom_component1::CreateDir : %s", opt.Name)
err := e.NextComponent().CreateDir(opt)
if err != nil {
log.Err("sample_custom_component1::CreateDir failed: %v", err)
return err
}
return nil
}
func (e *sample_custom_component1) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) {
log.Trace("sample_custom_component1::StreamDir : %s", options.Name)
attr, token, err := e.NextComponent().StreamDir(options)
if err != nil {
log.Err("sample_custom_component1::StreamDir failed: %v", err)
return nil, "", err
}
return attr, token, nil
}
func (e *sample_custom_component1) IsDirEmpty(options external.IsDirEmptyOptions) bool {
log.Trace("test2::IsDirEmpty : %s", options.Name)
empty := e.NextComponent().IsDirEmpty(options)
return empty
}
func (e *sample_custom_component1) DeleteDir(opt external.DeleteDirOptions) error {
log.Trace("sample_custom_component1::DeleteDir : %s", opt.Name)
err := e.NextComponent().DeleteDir(opt)
if err != nil {
log.Err("sample_custom_component1::DeleteDir failed: %v", err)
return err
}
return nil
}
func (e *sample_custom_component1) StageData(opt external.StageDataOptions) error {
log.Trace("sample_custom_component1::StageData : %s", opt.Name)
err := e.NextComponent().StageData(opt)
if err != nil {
log.Err("sample_custom_component1 StageData failed: %v", err)
return err
}
return nil
}
func (e *sample_custom_component1) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) {
log.Trace("sample_custom_component1::ReadInBuffer : %s", opt.Handle.Path)
n, err := e.NextComponent().ReadInBuffer(opt)
if err != nil {
log.Err("sample_custom_component1 ReadInBuffer failed: %v", err)
return 0, err
}
return n, nil
}
func (e *sample_custom_component1) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) {
log.Trace("sample_custom_component1::GetAttr : %s", options.Name)
attr, err = e.NextComponent().GetAttr(options)
if err != nil {
if os.IsNotExist(err) {
log.Trace("sample_custom_component1::GetAttr : File not found: %s", options.Name)
return nil, syscall.ENOENT
}
log.Err("sample_custom_component1 GetAttr failed: %v", err)
return nil, err
}
return attr, nil
}

Просмотреть файл

@ -17,17 +17,17 @@ import (
// This is a sample external component implementation that can be used as a reference to implement external components.
// The external component should implement the external.Component interface.
const (
CompName = "test2"
CompName = "sample_custom_component2"
Mb = 1024 * 1024
)
var _ external.Component = &test2{}
var _ external.Component = &sample_custom_component2{}
func (e *test2) SetName(name string) {
func (e *sample_custom_component2) SetName(name string) {
e.BaseComponent.SetName(name)
}
func (e *test2) SetNextComponent(nc external.Component) {
func (e *sample_custom_component2) SetNextComponent(nc external.Component) {
e.BaseComponent.SetNextComponent(nc)
}
@ -36,33 +36,33 @@ func GetExternalComponent() (string, func() external.Component) {
}
func NewexternalComponent() external.Component {
comp := &test2{}
comp := &sample_custom_component2{}
comp.SetName(CompName)
return comp
}
type test2 struct {
type sample_custom_component2 struct {
blockSize int64
externalPath string
external.BaseComponent
}
type test2Options struct {
type sample_custom_component2Options struct {
BlockSize int64 `config:"block-size-mb" yaml:"block-size-mb,omitempty"`
}
func (e *test2) Configure(isParent bool) error {
log.Info("test2:: Configure")
func (e *sample_custom_component2) Configure(isParent bool) error {
log.Info("sample_custom_component2:: Configure")
externalPath := os.Getenv("EXTERNAL_PATH")
if externalPath == "" {
log.Err("EXTERNAL_PATH not set")
return fmt.Errorf("EXTERNAL_PATH not set")
}
e.externalPath = externalPath
conf := test2Options{}
conf := sample_custom_component2Options{}
err := config.UnmarshalKey(e.Name(), &conf)
if err != nil {
log.Err("test2::Configure : config error [invalid config attributes]")
log.Err("sample_custom_component2::Configure : config error [invalid config attributes]")
return fmt.Errorf("error reading config for %s: %w", e.Name(), err)
}
if config.IsSet(e.Name()+".block-size-mb") && conf.BlockSize > 0 {
@ -71,8 +71,8 @@ func (e *test2) Configure(isParent bool) error {
return nil
}
func (e *test2) CreateFile(options external.CreateFileOptions) (*external.Handle, error) {
log.Info("test2::CreateFile")
func (e *sample_custom_component2) CreateFile(options external.CreateFileOptions) (*external.Handle, error) {
log.Info("sample_custom_component2::CreateFile")
filePath := filepath.Join(e.externalPath, options.Name)
fileHandle, err := os.OpenFile(filePath, os.O_CREATE, 0777)
if err != nil {
@ -86,8 +86,8 @@ func (e *test2) CreateFile(options external.CreateFileOptions) (*external.Handle
return handle, nil
}
func (e *test2) CreateDir(options external.CreateDirOptions) error {
log.Info("test2::CreateDir")
func (e *sample_custom_component2) CreateDir(options external.CreateDirOptions) error {
log.Info("sample_custom_component2::CreateDir")
dirPath := filepath.Join(e.externalPath, options.Name)
err := os.MkdirAll(dirPath, 0777)
if err != nil {
@ -97,8 +97,8 @@ func (e *test2) CreateDir(options external.CreateDirOptions) error {
return nil
}
func (e *test2) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) {
log.Info("test2::StreamDir")
func (e *sample_custom_component2) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) {
log.Info("sample_custom_component2::StreamDir")
var objAttrs []*internal.ObjAttr
path := formatListDirName(options.Name)
files, err := os.ReadDir(filepath.Join(e.externalPath, path))
@ -123,8 +123,8 @@ func (e *test2) StreamDir(options external.StreamDirOptions) ([]*external.ObjAtt
return objAttrs, "", nil
}
func (e *test2) IsDirEmpty(options external.IsDirEmptyOptions) bool {
log.Info("test2::IsDirEmpty")
func (e *sample_custom_component2) IsDirEmpty(options external.IsDirEmptyOptions) bool {
log.Info("sample_custom_component2::IsDirEmpty")
files, err := os.ReadDir(filepath.Join(e.externalPath, options.Name))
if err != nil {
log.Err("Failed to read directory %s", options.Name)
@ -133,8 +133,8 @@ func (e *test2) IsDirEmpty(options external.IsDirEmptyOptions) bool {
return len(files) == 0
}
func (e *test2) DeleteDir(options external.DeleteDirOptions) error {
log.Info("test2::DeleteDir")
func (e *sample_custom_component2) DeleteDir(options external.DeleteDirOptions) error {
log.Info("sample_custom_component2::DeleteDir")
dirPath := filepath.Join(e.externalPath, options.Name)
err := os.RemoveAll(dirPath)
if err != nil {
@ -144,8 +144,8 @@ func (e *test2) DeleteDir(options external.DeleteDirOptions) error {
return nil
}
func (e *test2) StageData(opt external.StageDataOptions) error {
log.Info("test2:: StageData")
func (e *sample_custom_component2) StageData(opt external.StageDataOptions) error {
log.Info("sample_custom_component2:: StageData")
filePath := filepath.Join(e.externalPath, opt.Name)
fileHandle, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY, 0777)
if err != nil {
@ -166,8 +166,8 @@ func (e *test2) StageData(opt external.StageDataOptions) error {
return nil
}
func (e *test2) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) {
log.Info("test2:: ReadInBuffer")
func (e *sample_custom_component2) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) {
log.Info("sample_custom_component2:: ReadInBuffer")
filePath := filepath.Join(e.externalPath, opt.Handle.Path)
fileHandle, err := os.OpenFile(filePath, os.O_RDONLY, 0777)
@ -185,11 +185,11 @@ func (e *test2) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err
return n, nil
}
func (e *test2) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) {
log.Info("test2::GetAttr for %s", options.Name)
func (e *sample_custom_component2) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) {
log.Info("sample_custom_component2::GetAttr for %s", options.Name)
fileAttr, err := os.Stat(filepath.Join(e.externalPath, options.Name))
if err != nil {
log.Trace("test2::GetAttr : Error getting file attributes: %s", err.Error())
log.Trace("sample_custom_component2::GetAttr : Error getting file attributes: %s", err.Error())
return &external.ObjAttr{}, err
}