Skip to content

Commit

Permalink
fix(dashboard): fix bugs that creates empty-name operations
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Feb 22, 2024
1 parent a636bec commit c7269b8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
33 changes: 19 additions & 14 deletions distribution/dashboard/internal/business/oceanbase/obtenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func ModifyOBTenantRootPassword(ctx context.Context, nn types.NamespacedName, ro
return buildDetailFromApiType(tenant), nil
}

func ReplayStandbyLog(ctx context.Context, nn types.NamespacedName, timestamp string) (*response.OBTenantDetail, error) {
func ReplayStandbyLog(ctx context.Context, nn types.NamespacedName, param *param.ReplayStandbyLog) (*response.OBTenantDetail, error) {
var err error
tenant, err := oceanbase.GetOBTenant(ctx, nn)
if err != nil {
Expand All @@ -357,13 +357,14 @@ func ReplayStandbyLog(ctx context.Context, nn types.NamespacedName, timestamp st
}
replayLogOp := v1alpha1.OBTenantOperation{
ObjectMeta: v1.ObjectMeta{
GenerateName: nn.Name + "-replay-log-" + rand.String(6),
Namespace: nn.Namespace,
Name: nn.Name + "-replay-log-" + rand.String(6),
Namespace: nn.Namespace,
},
Spec: v1alpha1.OBTenantOperationSpec{
Type: apiconst.TenantOpReplayLog,
ReplayUntil: &v1alpha1.RestoreUntilConfig{
Timestamp: &timestamp,
Timestamp: param.Timestamp,
Unlimited: param.Unlimited,
},
TargetTenant: &nn.Name,
},
Expand All @@ -386,8 +387,8 @@ func UpgradeTenantVersion(ctx context.Context, nn types.NamespacedName) (*respon
}
upgradeOp := v1alpha1.OBTenantOperation{
ObjectMeta: v1.ObjectMeta{
GenerateName: nn.Name + "-upgrade-" + rand.String(6),
Namespace: nn.Namespace,
Name: nn.Name + "-upgrade-" + rand.String(6),
Namespace: nn.Namespace,
},
Spec: v1alpha1.OBTenantOperationSpec{
Type: apiconst.TenantOpUpgrade,
Expand All @@ -407,26 +408,30 @@ func ChangeTenantRole(ctx context.Context, nn types.NamespacedName, p *param.Cha
if err != nil {
return nil, err
}
if tenant.Status.TenantRole == apitypes.TenantRole(p.TenantRole) {
return nil, oberr.NewBadRequest("The tenant is already " + string(p.TenantRole))
if tenant.Status.TenantRole == apiconst.TenantRolePrimary && p.Failover {
return nil, oberr.NewBadRequest("The tenant is already PRIMARY")
}
if p.Switchover && (tenant.Status.Source == nil || tenant.Status.Source.Tenant == nil) {
return nil, oberr.NewBadRequest("The tenant has no primary tenant")
}
changeRoleOp := v1alpha1.OBTenantOperation{
ObjectMeta: v1.ObjectMeta{
GenerateName: nn.Name + "-change-role-" + rand.String(6),
Namespace: nn.Namespace,
Name: nn.Name + "-change-role-" + rand.String(6),
Namespace: nn.Namespace,
},
Spec: v1alpha1.OBTenantOperationSpec{},
}
if p.Switchover {
changeRoleOp.Spec.Type = apiconst.TenantOpSwitchover
changeRoleOp.Spec.Switchover.PrimaryTenant = *tenant.Status.Source.Tenant
changeRoleOp.Spec.Switchover.StandbyTenant = nn.Name
} else {
changeRoleOp.Spec.Switchover = &v1alpha1.OBTenantOpSwitchoverSpec{
PrimaryTenant: *tenant.Status.Source.Tenant,
StandbyTenant: nn.Name,
}
} else if p.Failover {
changeRoleOp.Spec.Type = apiconst.TenantOpFailover
changeRoleOp.Spec.Failover.StandbyTenant = nn.Name
changeRoleOp.Spec.Failover = &v1alpha1.OBTenantOpFailoverSpec{
StandbyTenant: nn.Name,
}
}
_, err = oceanbase.CreateOBTenantOperation(ctx, &changeRoleOp)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions distribution/dashboard/internal/handler/obtenant_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ func ReplayStandbyLog(c *gin.Context) (*response.OBTenantDetail, error) {
if err != nil {
return nil, httpErr.NewBadRequest(err.Error())
}
if logReplayParam.Timestamp == nil {
return nil, httpErr.NewBadRequest("timestamp is required")
if !logReplayParam.Unlimited && logReplayParam.Timestamp == nil {
return nil, httpErr.NewBadRequest("timestamp is required if the restore is limited")
}
tenant, err := oceanbase.ReplayStandbyLog(c, types.NamespacedName{
Name: nn.Name,
Namespace: nn.Namespace,
}, *logReplayParam.Timestamp)
}, logReplayParam)
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
Expand Down Expand Up @@ -316,6 +316,9 @@ func ChangeTenantRole(c *gin.Context) (*response.OBTenantDetail, error) {
if err != nil {
return nil, httpErr.NewBadRequest(err.Error())
}
if !p.Failover != p.Switchover {
return nil, httpErr.NewBadRequest("one and only one of failover and switchover can be true")
}
tenant, err := oceanbase.ChangeTenantRole(c, types.NamespacedName{
Name: nn.Name,
Namespace: nn.Namespace,
Expand Down
4 changes: 2 additions & 2 deletions distribution/dashboard/internal/model/param/backup_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type ScheduleBase struct {
type BackupPolicyBase struct {
// Enum: NFS, OSS
DestType BackupDestType `json:"destType" binding:"required" example:"NFS"`
ArchivePath string `json:"archivePath"`
BakDataPath string `json:"bakDataPath"`
ArchivePath string `json:"archivePath" binding:"required"`
BakDataPath string `json:"bakDataPath" binding:"required"`

ScheduleBase `json:",inline"`

Expand Down
17 changes: 6 additions & 11 deletions distribution/dashboard/internal/model/param/obtenant_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type TenantSourceSpec struct {

type RestoreSourceSpec struct {
// Enum: OSS, NFS
Type BackupDestType `json:"type"`
ArchiveSource string `json:"archiveSource"`
BakDataSource string `json:"bakDataSource"`
Type BackupDestType `json:"type" binding:"required"`
ArchiveSource string `json:"archiveSource" binding:"required"`
BakDataSource string `json:"bakDataSource" binding:"required"`
OSSAccessID string `json:"ossAccessId,omitempty"`
OSSAccessKey string `json:"ossAccessKey,omitempty"`

Expand All @@ -54,14 +54,10 @@ type UnitConfig struct {
}

type RestoreUntilConfig struct {
Timestamp *string `json:"timestamp,omitempty"`
Timestamp *string `json:"timestamp,omitempty" example:"2024-02-23 17:47:00"`
Unlimited bool `json:"unlimited,omitempty"`
}

type ModifyUnitNumber struct {
UnitNumber int `json:"unitNum" binding:"required"`
}

type ChangeUserPassword struct {
// Description: The user name of the database account, only root is supported now.
User string `json:"user" binding:"required"`
Expand All @@ -71,9 +67,8 @@ type ChangeUserPassword struct {
type ReplayStandbyLog RestoreUntilConfig

type ChangeTenantRole struct {
// Enum: Primary, Standby
TenantRole TenantRole `json:"tenantRole" binding:"required"`
Switchover bool `json:"switchover,omitempty"`
Failover bool `json:"failover,omitempty"`
Switchover bool `json:"switchover,omitempty"`
}

type PatchUnitConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions distribution/dashboard/pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type httpErr struct {
children []*httpErr
}

var _ ObError = &httpErr{}

func (e *httpErr) Error() string {
return fmt.Sprintf("Error %s: %s", e.errorType, e.message)
}
Expand Down

0 comments on commit c7269b8

Please sign in to comment.