-
Notifications
You must be signed in to change notification settings - Fork 82
Writing Glusterd2 plugin
Currently Glusterd2 supports only compile time plugins. This behavior may change in future once Go plugins feature becomes stable.
Every plugin should implement the GlusterdPlugin interface
type GlusterdPlugin interface {
Name() string
SunRPCProgram() sunrpc.Program
RestRoutes() route.Routes
RegisterStepFuncs()
}
- Name - Name of the plugin
- SunRPCProgram - Register sunrpc program if a plugin requires communication between the spawned daemon(Ex: glusterfsd, bitd, quotad etc)
- RestRoutes - Register required REST routes here
- RegisterStepFuncs - Transaction Step functions which are required for each steps to be run in single node or multi node.
We have a utility to start writing a plugin. Run the below script with required plugin name so that it creates the required files to start working on the plugin.
./scripts/new-gd2-plugin.py <plugin-name>
Below example shows starting a plugin with name demo
./scripts/new-gd2-plugin.py demo
Run git status
to see the list of files created or changed.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: glusterd2/plugin/plugins.go
Untracked files:
(use "git add <file>..." to include in what will be committed)
plugins/demo/
Content of $SRC/plugins/demo
directory,
$ls plugins/demo
init.go
rest.go
Now start identifying the REST routes required for your plugin, add
the route pattern in init.go
and add implementation in rest.go
file.
For example, Geo-replication start REST API (init.go
)
route.Route{
Name: "GeoreplicationStart",
Method: "POST",
Pattern: "/geo-replication/{mastervolid}/{slavevolid}/start",
Version: 1,
HandlerFunc: georepStartHandler},
Example: $SRC/plugins/georeplication/init.go
Once the route is added, Framework will call the respective handler if
a requested URL matches the registered pattern. For example, above
pattern calls georepStartHandler
Example: $SRC/plugins/georeplication/rest.go
Each action need to run with lock and in multiple nodes. Glusterd2
provides Transaction framework to do the same. Register the required
Transaction function in init.go
.
For example, Geo-replication start command has to start gsyncd
daemon in all the nodes where Master volume has bricks. So while
calling georep create transaction, specify the nodes in which it needs
to be run.
Transaction framework also provides facility to rollback if a transaction step is failed.
Example: $SRC/plugins/georeplication/transactions.go
To persist the information/config for future use, plugin need to store its data in etcd store.
Example: $SRC/plugins/georeplication/store-utils.go
- Geo-replication session create https://github.com/gluster/glusterd2/pull/385
- Geo-replication session start https://github.com/gluster/glusterd2/pull/389