From 5d89a605134ff0595ff6a392a5f3d5439e704f24 Mon Sep 17 00:00:00 2001 From: rishubhjain Date: Tue, 23 Jan 2018 13:46:10 -0500 Subject: [PATCH 1/3] Adding Device Signed-off-by: rishubhjain --- glusterd2/commands/command.go | 2 + glusterd2/commands/devices/adddevice.go | 107 ++++++++++++++++++++++ glusterd2/commands/devices/commands.go | 28 ++++++ glusterd2/commands/devices/transaction.go | 31 +++++++ glusterd2/device/devicereq.go | 9 ++ glusterd2/device/deviceres.go | 21 +++++ 6 files changed, 198 insertions(+) create mode 100644 glusterd2/commands/devices/adddevice.go create mode 100644 glusterd2/commands/devices/commands.go create mode 100644 glusterd2/commands/devices/transaction.go create mode 100644 glusterd2/device/devicereq.go create mode 100644 glusterd2/device/deviceres.go diff --git a/glusterd2/commands/command.go b/glusterd2/commands/command.go index dccb74501..a9865ce3e 100644 --- a/glusterd2/commands/command.go +++ b/glusterd2/commands/command.go @@ -5,6 +5,7 @@ import ( "github.com/gluster/glusterd2/glusterd2/commands/peers" "github.com/gluster/glusterd2/glusterd2/commands/version" "github.com/gluster/glusterd2/glusterd2/commands/volumes" + "github.com/gluster/glusterd2/glusterd2/commands/devices" "github.com/gluster/glusterd2/glusterd2/servers/rest/route" ) @@ -21,4 +22,5 @@ var Commands = []Command{ &versioncommands.Command{}, &volumecommands.Command{}, &peercommands.Command{}, + &devicecommands.Command{}, } diff --git a/glusterd2/commands/devices/adddevice.go b/glusterd2/commands/devices/adddevice.go new file mode 100644 index 000000000..b2859dc19 --- /dev/null +++ b/glusterd2/commands/devices/adddevice.go @@ -0,0 +1,107 @@ +package devicecommands + +import ( + "context" + "encoding/json" + "net/http" + "github.com/pborman/uuid" + + device "github.com/gluster/glusterd2/glusterd2/device" + "github.com/coreos/etcd/clientv3" + restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils" + "github.com/gluster/glusterd2/glusterd2/store" + "github.com/gluster/glusterd2/pkg/api" + "github.com/gluster/glusterd2/glusterd2/transaction" + log "github.com/sirupsen/logrus" +) + + +func deviceAddHandler(w http.ResponseWriter, r *http.Request) { + // Collect inputs from URLi + ctx := r.Context() + req := new(device.AddDeviceReq) + if err := restutils.UnmarshalRequest(r, req); err != nil { + restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "", api.ErrCodeDefault) + return + } + nodeIDRaw := req.NodeID + deviceName := req.DeviceName + var deviceinfo device.DeviceInfo + deviceinfo.DeviceName = deviceName + nodeID := nodeIDRaw + if nodeID == nil { + restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Invalid Node ID", api.ErrCodeDefault) + return + } + deviceinfo.NodeID = nodeID + _, err := store.Store.Get(context.TODO(), deviceinfo.NodeID.String()) + if err != nil { + + restutils.SendHTTPError(ctx,w, http.StatusInternalServerError, "Node Id not found in store", api.ErrCodeDefault) + return + } + txn := transaction.NewTxn(ctx) + defer txn.Cleanup() + + lock, unlock, err := transaction.CreateLockSteps(deviceinfo.NodeID.String()) + if err != nil { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Unable to acquire lock", api.ErrCodeDefault) + return + } + + nodes := make([]uuid.UUID, 0) + nodes = append(nodes, deviceinfo.NodeID) + + txn.Nodes = nodes + txn.Steps = []*transaction.Step{ + lock, + { + DoFunc: "prepare-device.Commit", + Nodes: txn.Nodes, + }, + unlock, + } + txn.Ctx.Set("nodeid", deviceinfo.NodeID.String()) + txn.Ctx.Set("devicename", deviceinfo.DeviceName) + + err = txn.Do() + if err != nil { + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Transaction Failed", api.ErrCodeDefault) + return + } + // update device state + deviceinfo.State = device.DeviceEnabled + json1, err := json.Marshal(deviceinfo) + if err != nil { + log.WithField("error", err).Error("Failed to marshal the DeviceInfo object") + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Failed to marshal the DeviceInfo object", api.ErrCodeDefault) + return + } + + deviceDetails, _ := store.Store.Get(context.TODO(), "devices/" + nodeID.String(), clientv3.WithPrefix()) + + if len(deviceDetails.Kvs) > 0 { + for _, kv := range deviceDetails.Kvs { + + var v device.DeviceInfo + + _ = json.Unmarshal(kv.Value, &v) + + for _, val := range deviceinfo.DeviceName { + v.DeviceName = append(v.DeviceName, val) + } + json2, _ := json.Marshal(v) + _, err = store.Store.Put(context.TODO(), "devices/" + nodeID.String(), string(json2)) + } + } else { + _, err = store.Store.Put(context.TODO(), "devices/" + nodeID.String(), string(json1)) + if err != nil { + log.WithError(err).Error("Couldn't add deviceinfo to store") + restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Unable to add device to store", api.ErrCodeDefault) + return + } + } + restutils.SendHTTPResponse(ctx, w, http.StatusOK, deviceinfo) + +} + diff --git a/glusterd2/commands/devices/commands.go b/glusterd2/commands/devices/commands.go new file mode 100644 index 000000000..b8be10205 --- /dev/null +++ b/glusterd2/commands/devices/commands.go @@ -0,0 +1,28 @@ +package devicecommands + +import ( + "github.com/gluster/glusterd2/glusterd2/servers/rest/route" + "github.com/gluster/glusterd2/glusterd2/transaction" +) + +// Command is a holding struct used to implement the GlusterD Command interface +type Command struct { +} + +// Routes returns command routes. Required for the Command interface. +func (c *Command) Routes() route.Routes { + return route.Routes{ + route.Route{ + Name: "DeviceAdd", + Method: "POST", + Pattern: "/devices", + Version: 1, + HandlerFunc: deviceAddHandler}, + } +} + +// RegisterStepFuncs registers transaction step functions with +// Glusterd Transaction framework +func (c *Command) RegisterStepFuncs() { + transaction.RegisterStepFunc(txnPrepareDevice, "prepare-device.Commit") +} diff --git a/glusterd2/commands/devices/transaction.go b/glusterd2/commands/devices/transaction.go new file mode 100644 index 000000000..cf1ea2881 --- /dev/null +++ b/glusterd2/commands/devices/transaction.go @@ -0,0 +1,31 @@ +package devicecommands + + +import ( + "os/exec" + + device "github.com/gluster/glusterd2/glusterd2/device" + "github.com/gluster/glusterd2/glusterd2/transaction" +) + + +func txnPrepareDevice(c transaction.TxnCtx) error { + var deviceinfo device.DeviceInfo + if err := c.Get("nodeid", &deviceinfo.NodeID); err != nil { + return err + } + if err := c.Get("devicename", &deviceinfo.DeviceName); err != nil { + return err + } + for _, element := range deviceinfo.DeviceName{ + pvcreateCmd := exec.Command("pvcreate", "--metadatasize=128M", "--dataalignment=256K", element) + if err := pvcreateCmd.Run(); err != nil { + return err + } + vgcreateCmd := exec.Command("vgcreate", "vg"+element, element) + if err := vgcreateCmd.Run(); err != nil { + return err + } + } + return nil +} diff --git a/glusterd2/device/devicereq.go b/glusterd2/device/devicereq.go new file mode 100644 index 000000000..a2ddb61e7 --- /dev/null +++ b/glusterd2/device/devicereq.go @@ -0,0 +1,9 @@ +package device + +import "github.com/pborman/uuid" + +// Adding Device Request structure for Gd2 +type AddDeviceReq struct { + NodeID uuid.UUID `json:"nodeid"` + DeviceName []string `json:"devicename"` +} diff --git a/glusterd2/device/deviceres.go b/glusterd2/device/deviceres.go new file mode 100644 index 000000000..b064d3a22 --- /dev/null +++ b/glusterd2/device/deviceres.go @@ -0,0 +1,21 @@ +package device + +import "github.com/pborman/uuid" + +const ( + // DeviceEnabled represents enabled + DeviceEnabled = "Enabled" + + // DeviceFrozen represents frozen + DeviceFrozen = "Frozen" + + // DeviceEvacuated represents evacuated + DeviceEvacuated = "Evacuated" +) + +// DeviceInfo is the added device info +type DeviceInfo struct { + NodeID uuid.UUID `json:"nodeid"` + DeviceName []string `json:"devicename"` + State string `json:"devicestate"` +} From d3bfa94c865d080a100d84b594402ab436e472eb Mon Sep 17 00:00:00 2001 From: rishubhjain Date: Mon, 19 Feb 2018 05:52:31 -0500 Subject: [PATCH 2/3] testing --- glusterd2/commands/devices/adddevice.go | 44 +++++++++++++------------ glusterd2/commands/devices/commands.go | 2 +- glusterd2/device/store-utils.go | 11 ++++--- pkg/api/device_req_resp.go | 3 +- pkg/api/peer_req_resp.go | 5 +++ 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/glusterd2/commands/devices/adddevice.go b/glusterd2/commands/devices/adddevice.go index d3c224497..be9b0e38b 100644 --- a/glusterd2/commands/devices/adddevice.go +++ b/glusterd2/commands/devices/adddevice.go @@ -2,6 +2,7 @@ package devicecommands import ( "net/http" + "fmt" "github.com/gluster/glusterd2/glusterd2/device" "github.com/gluster/glusterd2/glusterd2/gdctx" @@ -11,6 +12,7 @@ import ( "github.com/gluster/glusterd2/pkg/api" "github.com/pborman/uuid" + "github.com/gorilla/mux" ) func deviceAddHandler(w http.ResponseWriter, r *http.Request) { @@ -24,31 +26,31 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Unable to marshal request", api.ErrCodeDefault) return } - deviceinfo := api.Device{ - PeerID: req.PeerID, - } - for _, name := range req.Names { - tempInfo := api.Info{ + peerID := mux.Vars(r)["peerid"] + if peerID == "" { + restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "peerid not present in request", api.ErrCodeDefault) + return + } + fmt.Printf("Printing peer ID %s", peerID) + p, err := peer.GetPeer(peerID) + if err != nil { + logger.WithError(err).WithField("peerid", peerID).Error("Peer ID not found in store") + restutils.SendHTTPError(ctx, w, http.StatusNotFound, "Peer Id not found in store", api.ErrCodeDefault) + return + } + var v []api.DeviceInfo + fmt.Printf("Printing Peer %s",p) + for _, name := range req.Devices { + tempInfo := api.DeviceInfo{ Name: name, } - deviceinfo.Detail = append(deviceinfo.Detail, tempInfo) - } - if req.PeerID == nil { - restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Peer ID not found in request", api.ErrCodeDefault) - return - } - - _, err := peer.GetPeer(deviceinfo.PeerID.String()) - if err != nil { - logger.WithError(err).WithField("peerid", req.PeerID).Error("Peer ID not found in store") - restutils.SendHTTPError(ctx, w, http.StatusNotFound, "Peer Id not found in store", api.ErrCodeDefault) - return + v = append(v, tempInfo) } txn := transaction.NewTxn(ctx) defer txn.Cleanup() nodes := make([]uuid.UUID, 0) - nodes = append(nodes, deviceinfo.PeerID) + nodes = append(nodes, uuid.UUID(peerID)) txn.Nodes = nodes txn.Steps = []*transaction.Step{ @@ -57,8 +59,8 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { Nodes: txn.Nodes, }, } - txn.Ctx.Set("peerid", deviceinfo.PeerID.String()) - txn.Ctx.Set("device-details", deviceinfo.Detail) + txn.Ctx.Set("peerid", peerID) + txn.Ctx.Set("device-details", v) err = txn.Do() if err != nil { @@ -66,6 +68,6 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, "Transaction Failed", api.ErrCodeDefault) return } - deviceInfo, _ := device.GetDevice(req.PeerID.String()) + deviceInfo, _ := device.GetDevice(peerID) restutils.SendHTTPResponse(ctx, w, http.StatusOK, deviceInfo) } diff --git a/glusterd2/commands/devices/commands.go b/glusterd2/commands/devices/commands.go index 7f97360d1..0aacf2b45 100644 --- a/glusterd2/commands/devices/commands.go +++ b/glusterd2/commands/devices/commands.go @@ -15,7 +15,7 @@ func (c *Command) Routes() route.Routes { route.Route{ Name: "DeviceAdd", Method: "POST", - Pattern: "/devices", + Pattern: "/peers/{peerid}/devices", Version: 1, HandlerFunc: deviceAddHandler}, } diff --git a/glusterd2/device/store-utils.go b/glusterd2/device/store-utils.go index d73f9ad0d..778921b2a 100644 --- a/glusterd2/device/store-utils.go +++ b/glusterd2/device/store-utils.go @@ -4,6 +4,7 @@ package device import ( "context" "encoding/json" + "fmt" "github.com/gluster/glusterd2/glusterd2/store" "github.com/gluster/glusterd2/pkg/api" @@ -11,21 +12,23 @@ import ( const ( devicePrefix string = "devices/" + peerPrefix string = "peers/" ) // GetDevice returns devices of specified peer from the store func GetDevice(peerid string) (*api.Device, error) { - resp, err := store.Store.Get(context.TODO(), devicePrefix+peerid) + resp, err := store.Store.Get(context.TODO(), peerPrefix+peerid+devicePrefix) if err != nil { return nil, err } - if len(resp.Kvs) > 0 { + fmt.Printf("Printing Get Device %s", resp) + /*if len(resp.Kvs) > 0 { var deviceDetail api.Device if err := json.Unmarshal(resp.Kvs[0].Value, &deviceDetail); err != nil { return nil, err } return &deviceDetail, nil - } + }*/ return nil, nil } @@ -39,7 +42,7 @@ func AddOrUpdateDevice(d *api.Device) error { idStr := d.PeerID.String() - if _, err := store.Store.Put(context.TODO(), devicePrefix+idStr, string(json)); err != nil { + if _, err := store.Store.Put(context.TODO(), peerPrefix+idStr+devicePrefix, string(json)); err != nil { return err } diff --git a/pkg/api/device_req_resp.go b/pkg/api/device_req_resp.go index 12e2664cf..a222f2c64 100644 --- a/pkg/api/device_req_resp.go +++ b/pkg/api/device_req_resp.go @@ -15,8 +15,7 @@ const ( // AddDeviceReq structure type AddDeviceReq struct { - PeerID uuid.UUID `json:"peer-id"` - Names []string `json:"names"` + Devices []string `json:"devices"` } // Device is the added device info diff --git a/pkg/api/peer_req_resp.go b/pkg/api/peer_req_resp.go index 5cd4f091d..6106a75c4 100644 --- a/pkg/api/peer_req_resp.go +++ b/pkg/api/peer_req_resp.go @@ -18,6 +18,11 @@ type PeerAddReq struct { MetaData map[string]string `json:"metadata"` } +type DeviceInfo struct { + Name string `json:"name"` + State string `json:"state"` +} + // PeerAddResp is the success response sent to a PeerAddReq request type PeerAddResp Peer From 52985ae7257b44ac148bb3904d8ff4057b8f439a Mon Sep 17 00:00:00 2001 From: rishubhjain Date: Mon, 26 Feb 2018 03:54:07 -0500 Subject: [PATCH 3/3] Refactoring code --- glusterd2/commands/command.go | 2 - glusterd2/commands/devices/commands.go | 32 ------------- glusterd2/plugin/plugins.go | 2 + .../device/api/req.go | 4 +- plugins/device/api/res.go | 9 ++++ plugins/device/init.go | 43 ++++++++++++++++++ .../adddevice.go => plugins/device/rest.go | 13 ++---- {glusterd2 => plugins}/device/store-utils.go | 5 +- .../devices => plugins/device}/transaction.go | 14 +++--- plugins/georeplication/.init.go.swp | Bin 0 -> 16384 bytes 10 files changed, 66 insertions(+), 58 deletions(-) delete mode 100644 glusterd2/commands/devices/commands.go rename pkg/api/device_req_resp.go => plugins/device/api/req.go (73%) create mode 100644 plugins/device/api/res.go create mode 100644 plugins/device/init.go rename glusterd2/commands/devices/adddevice.go => plugins/device/rest.go (90%) rename {glusterd2 => plugins}/device/store-utils.go (88%) rename {glusterd2/commands/devices => plugins/device}/transaction.go (81%) create mode 100644 plugins/georeplication/.init.go.swp diff --git a/glusterd2/commands/command.go b/glusterd2/commands/command.go index f5ec4b3f7..3ea3c9371 100644 --- a/glusterd2/commands/command.go +++ b/glusterd2/commands/command.go @@ -2,7 +2,6 @@ package commands import ( - "github.com/gluster/glusterd2/glusterd2/commands/devices" "github.com/gluster/glusterd2/glusterd2/commands/global" "github.com/gluster/glusterd2/glusterd2/commands/peers" "github.com/gluster/glusterd2/glusterd2/commands/version" @@ -23,6 +22,5 @@ var Commands = []Command{ &versioncommands.Command{}, &volumecommands.Command{}, &peercommands.Command{}, - &devicecommands.Command{}, &globalcommands.Command{}, } diff --git a/glusterd2/commands/devices/commands.go b/glusterd2/commands/devices/commands.go deleted file mode 100644 index 15472a6bd..000000000 --- a/glusterd2/commands/devices/commands.go +++ /dev/null @@ -1,32 +0,0 @@ -package devicecommands - -import ( - "github.com/gluster/glusterd2/glusterd2/servers/rest/route" - "github.com/gluster/glusterd2/glusterd2/transaction" - "github.com/gluster/glusterd2/pkg/api" - "github.com/gluster/glusterd2/pkg/utils" -) - -// Command is a holding struct used to implement the GlusterD Command interface -type Command struct { -} - -// Routes returns command routes. Required for the Command interface. -func (c *Command) Routes() route.Routes { - return route.Routes{ - route.Route{ - Name: "DeviceAdd", - Method: "POST", - Pattern: "/peers/{peerid}/devices", - Version: 1, - RequestType: utils.GetTypeString((*api.AddDeviceReq)(nil)), - ResponseType: utils.GetTypeString((*api.DeviceAddResp)(nil)), - HandlerFunc: deviceAddHandler}, - } -} - -// RegisterStepFuncs registers transaction step functions with -// Glusterd Transaction framework -func (c *Command) RegisterStepFuncs() { - transaction.RegisterStepFunc(txnPrepareDevice, "prepare-device") -} diff --git a/glusterd2/plugin/plugins.go b/glusterd2/plugin/plugins.go index 34cf0ae98..f59ad13e1 100644 --- a/glusterd2/plugin/plugins.go +++ b/glusterd2/plugin/plugins.go @@ -8,6 +8,7 @@ import ( "github.com/gluster/glusterd2/plugins/georeplication" "github.com/gluster/glusterd2/plugins/glustershd" "github.com/gluster/glusterd2/plugins/quota" + "github.com/gluster/glusterd2/plugins/device" ) // PluginsList is a list of plugins which implements GlusterdPlugin interface @@ -17,4 +18,5 @@ var PluginsList = []GlusterdPlugin{ "a.Plugin{}, &events.Plugin{}, &glustershd.Plugin{}, + &device.Plugin{}, } diff --git a/pkg/api/device_req_resp.go b/plugins/device/api/req.go similarity index 73% rename from pkg/api/device_req_resp.go rename to plugins/device/api/req.go index d35578084..4d1f68353 100644 --- a/pkg/api/device_req_resp.go +++ b/plugins/device/api/req.go @@ -1,4 +1,4 @@ -package api +package device const ( // DeviceEnabled represents enabled @@ -16,5 +16,3 @@ type AddDeviceReq struct { Devices []string `json:"devices"` } -// DeviceAddResp is the success response sent to a AddDeviceReq request -type DeviceAddResp Peer diff --git a/plugins/device/api/res.go b/plugins/device/api/res.go new file mode 100644 index 000000000..f07901746 --- /dev/null +++ b/plugins/device/api/res.go @@ -0,0 +1,9 @@ +package device + +import ( + "github.com/gluster/glusterd2/pkg/api" +) + +// DeviceAddResp is the success response sent to a AddDeviceReq request +type DeviceAddResp api.Peer + diff --git a/plugins/device/init.go b/plugins/device/init.go new file mode 100644 index 000000000..e5b6bde5c --- /dev/null +++ b/plugins/device/init.go @@ -0,0 +1,43 @@ +package device + +import ( + "github.com/gluster/glusterd2/glusterd2/servers/rest/route" + "github.com/gluster/glusterd2/glusterd2/transaction" + deviceapi "github.com/gluster/glusterd2/plugins/device/api" + "github.com/gluster/glusterd2/pkg/utils" + "github.com/gluster/glusterd2/pkg/sunrpc" +) + +// Plugin is a structure which implements GlusterdPlugin interface +type Plugin struct { +} + +// Name returns name of plugin +func (p *Plugin) Name() string { + return "georeplication" +} + +// SunRPCProgram returns sunrpc program to register with Glusterd +func (p *Plugin) SunRPCProgram() sunrpc.Program { + return nil +} + +// Routes returns list of REST API routes to register with Glusterd. +func (p *Plugin) RestRoutes() route.Routes { + return route.Routes{ + route.Route{ + Name: "DeviceAdd", + Method: "POST", + Pattern: "/peers/{peerid}/devices", + Version: 1, + RequestType: utils.GetTypeString((*deviceapi.AddDeviceReq)(nil)), + ResponseType: utils.GetTypeString((*deviceapi.DeviceAddResp)(nil)), + HandlerFunc: deviceAddHandler}, + } +} + +// RegisterStepFuncs registers transaction step functions with +// Glusterd Transaction framework +func (p *Plugin) RegisterStepFuncs() { + transaction.RegisterStepFunc(txnPrepareDevice, "prepare-device") +} diff --git a/glusterd2/commands/devices/adddevice.go b/plugins/device/rest.go similarity index 90% rename from glusterd2/commands/devices/adddevice.go rename to plugins/device/rest.go index cc0771229..9fa42749b 100644 --- a/glusterd2/commands/devices/adddevice.go +++ b/plugins/device/rest.go @@ -1,4 +1,4 @@ -package devicecommands +package device import ( "net/http" @@ -8,6 +8,7 @@ import ( restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils" "github.com/gluster/glusterd2/glusterd2/transaction" "github.com/gluster/glusterd2/pkg/api" + deviceapi "github.com/gluster/glusterd2/plugins/device/api" "github.com/gorilla/mux" "github.com/pborman/uuid" @@ -18,7 +19,7 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() logger := gdctx.GetReqLogger(ctx) - req := new(api.AddDeviceReq) + req := new(deviceapi.AddDeviceReq) if err := restutils.UnmarshalRequest(r, req); err != nil { logger.WithError(err).Error("Failed to Unmarshal request") restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Unable to marshal request", api.ErrCodeDefault) @@ -35,14 +36,6 @@ func deviceAddHandler(w http.ResponseWriter, r *http.Request) { restutils.SendHTTPError(ctx, w, http.StatusNotFound, "Peer Id not found in store", api.ErrCodeDefault) return } - /* - var deviceList []api.DeviceInfo - for _, name := range req.Devices { - tempDevice := api.DeviceInfo{ - Name: name, - } - deviceList = append(deviceList, tempDevice) - }*/ txn := transaction.NewTxn(ctx) defer txn.Cleanup() lock, unlock, err := transaction.CreateLockSteps(string(peerInfo.ID)) diff --git a/glusterd2/device/store-utils.go b/plugins/device/store-utils.go similarity index 88% rename from glusterd2/device/store-utils.go rename to plugins/device/store-utils.go index 56a0957bd..4f3ffa09c 100644 --- a/glusterd2/device/store-utils.go +++ b/plugins/device/store-utils.go @@ -1,4 +1,3 @@ -// Package device stores device information in the store package device import ( @@ -32,9 +31,7 @@ func AddDevices(devices []api.DeviceInfo, peerID string) error { return err } if deviceDetails != nil { - for _, element := range devices { - devices = append(deviceDetails, element) - } + devices = append(devices, deviceDetails...) } deviceJSON, err := json.Marshal(devices) if err != nil { diff --git a/glusterd2/commands/devices/transaction.go b/plugins/device/transaction.go similarity index 81% rename from glusterd2/commands/devices/transaction.go rename to plugins/device/transaction.go index 48d6d5744..6052f0a57 100644 --- a/glusterd2/commands/devices/transaction.go +++ b/plugins/device/transaction.go @@ -1,12 +1,12 @@ -package devicecommands +package device import ( "os/exec" "strings" - "github.com/gluster/glusterd2/glusterd2/device" "github.com/gluster/glusterd2/glusterd2/transaction" "github.com/gluster/glusterd2/pkg/api" + deviceapi "github.com/gluster/glusterd2/plugins/device/api" "github.com/pborman/uuid" log "github.com/sirupsen/logrus" @@ -14,7 +14,7 @@ import ( func txnPrepareDevice(c transaction.TxnCtx) error { var peerID uuid.UUID - var req api.AddDeviceReq + var req deviceapi.AddDeviceReq var deviceList []api.DeviceInfo if err := c.Get("peerid", peerID); err != nil { c.Logger().WithError(err).Error("Failed transaction, cannot find peer-id") @@ -34,18 +34,18 @@ func txnPrepareDevice(c transaction.TxnCtx) error { pvcreateCmd := exec.Command("pvcreate", "--metadatasize=128M", "--dataalignment=256K", element.Name) if err := pvcreateCmd.Run(); err != nil { c.Logger().WithError(err).WithField("device", element.Name).Error("pvcreate failed for device") - deviceList[index].State = api.DeviceFailed + deviceList[index].State = deviceapi.DeviceFailed continue } vgcreateCmd := exec.Command("vgcreate", strings.Replace("vg"+element.Name, "/", "-", -1), element.Name) if err := vgcreateCmd.Run(); err != nil { c.Logger().WithError(err).WithField("device", element.Name).Error("vgcreate failed for device") - deviceList[index].State = api.DeviceFailed + deviceList[index].State = deviceapi.DeviceFailed continue } - deviceList[index].State = api.DeviceEnabled + deviceList[index].State = deviceapi.DeviceEnabled } - err := device.AddDevices(deviceList, peerID.String()) + err := AddDevices(deviceList, peerID.String()) if err != nil { log.WithError(err).Error("Couldn't add deviceinfo to store") } diff --git a/plugins/georeplication/.init.go.swp b/plugins/georeplication/.init.go.swp new file mode 100644 index 0000000000000000000000000000000000000000..df1f49c76fc45787424b9f7fdb1b852d86f3871f GIT binary patch literal 16384 zcmeI2O^g&p6vsD@W8>Cc+!X$6JmmiK@Y~0;o@DQi5jC2;e=j1c=2CdJ;Sim4Bb0HjaG->Hd9^o z=DmMc_f);AV_PQ=9HKkRj}shg2zi2?K6>$w)r;O)NeB-^sfurR_@QI_%}~g4^1nvd zvb`Xq(W}a!<%TauJUng*?pUrToAI%-6SgeZkA-Bsb8c+6B0qM$Kv*sdIg5PHv85LV zmKS)k?1mZkO_5Q+C@@HYRbQcl6&Hx5p0ndX+z-n-931SBy zgZDrHCc&fN0dNJ$mrLLrcpEgq5%3sT2Y$o7`wn~xJ^&{{396@3v^ zAY_h=;NQr|emiLRjH~v$sNUpJukU}B&5kpfUYpyjDo!#k(0&(H$F`)XYD;{5T2!)x zXl|KivsU{==m+p~u9Va|#AGvU=ytR;UYXFv&!I+INKt&#_L912Y7dgCJd7nP*VNzk zK$okrXb$VM6~RcB*90hIZdg4GkMY$D!O|NL$9@AUb5h5YXqg z^z1Ck@;hIj={k_*vhKsFYrUO)EDWYRx5h-byXWlf^Zd5jEn7W|==)w{&T4bk3METF zImwq~g|@eHurg86SNfia+KmlYJ#H=_y!t;A+<-@>FEqHgfWU6Nr2f{scIyt=7Z*It ziYxQIoAlt}9-l$oQ1`Nhyp9vc@`izDDQ*>gkrjEGc=82V(G2KtJ+Bz;VBT=5b}a5> zG?B8u@L&@6^2V~4`K<77Oo3aI6~@3fT+dz6zU7UiF2m@~Jt>xe`K(~_bui^z{y=O# z%|M2(f{Xhb(vlg-Z? zG13+?8Gnk=jW^Y$Z9Ne0T*e4o*%Q>qK!}D@v{tE4&^^@yx)sLdVRw+848*&`{A5I) zdJ}klzYp~|s8z?RJajP!fEywXc;uAR0`166b-KRjniTuJRnvSflyF;m9?nv~KWen1 z+>qQ0T>bT`sQayf`Tzy=267dioQ)XOlB#C0BXzU1$P?5~%VW;yOw)6k)N4gPYq3Cz zu2P-q0Y+O>w!<(@BqOE4o7ksaORG@2UDb34Ja)eKOrZ+25*PwvrextqN?J*`DiH(` za!E%CiEL-uc3C>n>g=W`YW}|x^XnIZn*U=eo*ds|j(-|F34X`CUCr$$ftt&Ij!F(# z2F|11OKJO~%7!_N0!9I&fKk9GU=%P47zK<1MuGpM0$AkfnaGsquNjTXlYw6E5o*z5 zGo3f_+mbHos8x~jSlDWLvV`eYPLrKQgj<@$YDEF7{dXYu;2HImF@ sVRI^z)^AK@=N4cJnXD{ZC@ySF=ac%aIY|cWhPjMP(!4cWq)^)AFT89n{r~^~ literal 0 HcmV?d00001