Skip to content

Commit

Permalink
Added support to perform cluster promotion/demotion
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <[email protected]>
  • Loading branch information
UtkarshBhatthere committed Oct 11, 2024
1 parent ee3100f commit b6459b2
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 125 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ jobs:
- name: Verify RBD mirror
run : ~/actionutils.sh remote_verify_rbd_mirroring

- name: Failover site A to Site B
run : ~/actionutils.sh remote_failover_to_siteb

- name: Failback to Site A
run : ~/actionutils.sh remote_failback_to_sitea

- name: Disable RBD mirror
run : ~/actionutils.sh remote_disable_rbd_mirroring

Expand Down
29 changes: 29 additions & 0 deletions docs/reference/commands/remote-replication-rbd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,32 @@ Usage:
--force forcefully disable replication for rbd resource
``promote``
----------

Promote local cluster to primary

.. code-block:: none
microceph remote replication rbd promote [flags]
.. code-block:: none
--remote remote MicroCeph cluster name
--force forcefully promote site to primary
``demote``
------------

Demote local cluster to secondary

Usage:

.. code-block:: none
microceph remote replication rbd demote [flags]
.. code-block:: none
--remote remote MicroCeph cluster name
1 change: 1 addition & 0 deletions microceph/api/ops_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var opsReplicationCmd = rest.Endpoint{
// List Replications
var opsReplicationWorkloadCmd = rest.Endpoint{
Path: "ops/replication/{wl}",
Put: rest.EndpointAction{Handler: cmdOpsReplication, ProxyTarget: false},
Get: rest.EndpointAction{Handler: cmdOpsReplication, ProxyTarget: false},
}

Expand Down
104 changes: 8 additions & 96 deletions microceph/api/types/replication.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package types

import (
"fmt"
"net/url"
"strings"

"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microceph/microceph/constants"
)

Expand All @@ -14,11 +9,16 @@ type ReplicationRequestType string

// This value is split till '-' to get the API request value.
const (
// Put Requests
EnableReplicationRequest ReplicationRequestType = "PUT-" + constants.EventEnableReplication
ConfigureReplicationRequest ReplicationRequestType = "PUT-" + constants.EventConfigureReplication
DisableReplicationRequest ReplicationRequestType = "DELETE-" + constants.EventDisableReplication
StatusReplicationRequest ReplicationRequestType = "GET-" + constants.EventStatusReplication
ListReplicationRequest ReplicationRequestType = "GET-" + constants.EventListReplication
PromoteReplicationRequest ReplicationRequestType = "PUT-" + constants.EventPromoteReplication
DemoteReplicationRequest ReplicationRequestType = "PUT-" + constants.EventDemoteReplication
// Delete Requests
DisableReplicationRequest ReplicationRequestType = "DELETE-" + constants.EventDisableReplication
// Get Requests
StatusReplicationRequest ReplicationRequestType = "GET-" + constants.EventStatusReplication
ListReplicationRequest ReplicationRequestType = "GET-" + constants.EventListReplication
)

type CephWorkloadType string
Expand All @@ -35,91 +35,3 @@ type ReplicationRequest interface {
GetAPIRequestType() string
GetWorkloadRequestType() string
}

// Slices
type MirrorPool struct {
Name string
Mode RbdResourceType
}

type MirrorImage struct {
Name string
Mode RbdReplicationType
}

type MirrorPools []MirrorPool
type MirrorImages []MirrorImage

// ################################## RBD Replication Request ##################################
type RbdResourceType string
type RbdReplicationDirection string

const (
RbdReplicationDirectionRXOnly RbdReplicationDirection = "rx-only"
RbdReplicationDirectionRXTX RbdReplicationDirection = "rx-tx"
)

const (
RbdResourceDisabled RbdResourceType = "disabled"
RbdResourcePool RbdResourceType = "pool"
RbdResourceImage RbdResourceType = "image"
)

type RbdReplicationType string

const (
RbdReplicationDisabled RbdReplicationType = "disable"
RbdReplicationJournaling RbdReplicationType = "journal"
RbdReplicationSnapshot RbdReplicationType = "snapshot"
)

type RbdReplicationRequest struct {
SourcePool string `json:"source_pool" yaml:"source_pool"`
SourceImage string `json:"source_image" yaml:"source_image"`
RemoteName string `json:"remote" yaml:"remote"`
// snapshot in d,h,m format
Schedule string `json:"schedule" yaml:"schedule"`
ReplicationType RbdReplicationType `json:"replication_type" yaml:"replication_type"`
ResourceType RbdResourceType `json:"resource_type" yaml:"resource_type"`
RequestType ReplicationRequestType `json:"request_type" yaml:"request_type"`
IsForceOp bool `json:"force" yaml:"force"`
SkipAutoEnable bool `json:"skipAutoEnable" yaml:"skipAutoEnable"`
}

func (req RbdReplicationRequest) GetWorkloadType() CephWorkloadType {
return RbdWorkload
}

func (req RbdReplicationRequest) GetAPIObjectId() string {
// If both Pool and Image values are present encode for query.
if len(req.SourceImage) != 0 && len(req.SourcePool) != 0 {
resource := url.QueryEscape(fmt.Sprintf("%s/%s", req.SourcePool, req.SourceImage))
// TODO: Make this a debug print.
logger.Infof("REPAPI: Resource: %s", resource)
return resource
}

return req.SourcePool
}

func (req RbdReplicationRequest) GetAPIRequestType() string {
frags := strings.Split(string(req.RequestType), "-")
// TODO: Make this a debug print.
logger.Infof("REPAPI: API frags: %v", frags)
if len(frags) == 0 {
return ""
}

return frags[0]
}

func (req RbdReplicationRequest) GetWorkloadRequestType() string {
frags := strings.Split(string(req.RequestType), "-")
// TODO: Make this a debug print.
logger.Infof("REPAPI: Workload frags: %v", frags)
if len(frags) < 2 {
return ""
}

return frags[1]
}
82 changes: 82 additions & 0 deletions microceph/api/types/replication_rbd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package types

import (
"fmt"
"net/url"
"strings"

"github.com/canonical/lxd/shared/logger"
)

// Types for RBD Pool status table.
type RbdPoolStatusImageBrief struct {
Name string `json:"name" yaml:"name"`
Expand Down Expand Up @@ -56,3 +64,77 @@ type RbdPoolBrief struct {
}

type RbdPoolList []RbdPoolBrief

// ################################## RBD Replication Request ##################################
type RbdResourceType string
type RbdReplicationDirection string

const (
RbdReplicationDirectionRXOnly RbdReplicationDirection = "rx-only"
RbdReplicationDirectionRXTX RbdReplicationDirection = "rx-tx"
)

const (
RbdResourceDisabled RbdResourceType = "disabled"
RbdResourcePool RbdResourceType = "pool"
RbdResourceImage RbdResourceType = "image"
)

type RbdReplicationType string

const (
RbdReplicationDisabled RbdReplicationType = "disable"
RbdReplicationJournaling RbdReplicationType = "journal"
RbdReplicationSnapshot RbdReplicationType = "snapshot"
)

type RbdReplicationRequest struct {
SourcePool string `json:"source_pool" yaml:"source_pool"`
SourceImage string `json:"source_image" yaml:"source_image"`
RemoteName string `json:"remote" yaml:"remote"`
// snapshot in d,h,m format
Schedule string `json:"schedule" yaml:"schedule"`
ReplicationType RbdReplicationType `json:"replication_type" yaml:"replication_type"`
ResourceType RbdResourceType `json:"resource_type" yaml:"resource_type"`
RequestType ReplicationRequestType `json:"request_type" yaml:"request_type"`
IsForceOp bool `json:"force" yaml:"force"`
SkipAutoEnable bool `json:"skipAutoEnable" yaml:"skipAutoEnable"`
}

func (req RbdReplicationRequest) GetWorkloadType() CephWorkloadType {
return RbdWorkload
}

func (req RbdReplicationRequest) GetAPIObjectId() string {
// If both Pool and Image values are present encode for query.
if len(req.SourceImage) != 0 && len(req.SourcePool) != 0 {
resource := url.QueryEscape(fmt.Sprintf("%s/%s", req.SourcePool, req.SourceImage))
// TODO: Make this a debug print.
logger.Infof("REPAPI: Resource: %s", resource)
return resource
}

return req.SourcePool
}

func (req RbdReplicationRequest) GetAPIRequestType() string {
frags := strings.Split(string(req.RequestType), "-")
// TODO: Make this a debug print.
logger.Infof("REPAPI: API frags: %v", frags)
if len(frags) == 0 {
return ""
}

return frags[0]
}

func (req RbdReplicationRequest) GetWorkloadRequestType() string {
frags := strings.Split(string(req.RequestType), "-")
// TODO: Make this a debug print.
logger.Infof("REPAPI: Workload frags: %v", frags)
if len(frags) < 2 {
return ""
}

return frags[1]
}
Loading

0 comments on commit b6459b2

Please sign in to comment.