Skip to content

Commit

Permalink
Fix(migrate): chunkserver migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxianfei1 committed Dec 4, 2023
1 parent 9d83a9c commit a389709
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cli/command/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ var (
// chunkserevr (curvebs)
MIGRATE_CHUNKSERVER_STEPS = []int{
playbook.BACKUP_ETCD_DATA,
playbook.STOP_SERVICE,
playbook.CLEAN_SERVICE, // only container
// playbook.STOP_SERVICE,
// playbook.CLEAN_SERVICE, // only container
playbook.PULL_IMAGE,
playbook.CREATE_CONTAINER,
playbook.SYNC_CONFIG,
playbook.CREATE_PHYSICAL_POOL,
playbook.START_CHUNKSERVER,
playbook.CREATE_LOGICAL_POOL,
playbook.MARK_CHUNKSERVER_PENGDDING,
}

// metaserver (curvefs)
Expand Down Expand Up @@ -199,7 +200,8 @@ func genMigratePlaybook(curveadm *cli.CurveAdm,
// configs
config := dcs2add
switch step {
case playbook.STOP_SERVICE,
case playbook.MARK_CHUNKSERVER_PENGDDING,
playbook.STOP_SERVICE,
playbook.CLEAN_SERVICE:
config = dcs2del
case playbook.BACKUP_ETCD_DATA:
Expand Down
3 changes: 3 additions & 0 deletions internal/playbook/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
GET_CLIENT_STATUS
INSTALL_CLIENT
UNINSTALL_CLIENT
MARK_CHUNKSERVER_PENGDDING

// bs
FORMAT_CHUNKFILE_POOL
Expand Down Expand Up @@ -247,6 +248,8 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
t, err = comm.NewInstallClientTask(curveadm, config.GetCC(i))
case UNINSTALL_CLIENT:
t, err = comm.NewUninstallClientTask(curveadm, nil)
case MARK_CHUNKSERVER_PENGDDING:
t, err = comm.NewMarkChunkserverPendding(curveadm, nil)
// bs
case FORMAT_CHUNKFILE_POOL:
t, err = bs.NewFormatChunkfilePoolTask(curveadm, config.GetFC(i))
Expand Down
77 changes: 77 additions & 0 deletions internal/task/task/common/mark_chunkserver_pendding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: CurveAdm
* Created Date: 2023-11-30
* Author: Xianfei Cao (caoxianfei1)
*/

package common

import (
"fmt"

"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/internal/configure/topology"
"github.com/opencurve/curveadm/internal/task/step"
"github.com/opencurve/curveadm/internal/task/task"
tui "github.com/opencurve/curveadm/internal/tui/common"
)

func NewMarkChunkserverPendding(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {
serviceId := curveadm.GetServiceId(dc.GetId())
containerId, err := curveadm.GetContainerId(serviceId)
if curveadm.IsSkip(dc) {
return nil, nil
} else if err != nil {
return nil, err
}

hc, err := curveadm.GetHost(dc.GetHost())
if err != nil {
return nil, err
}

// new task
subname := fmt.Sprintf("host=%s role=%s containerId=%s",
dc.GetHost(), dc.GetRole(), tui.TrimContainerId(containerId))
t := task.NewTask("Mark chunkserver pendding", subname, hc.GetSSHConfig())

var out string
var success bool
host, role := dc.GetHost(), dc.GetRole()
cmd := "curvebs-tool -op=set_chunkserver -chunkserver_id=%s -chunkserver_status=pendding"
t.AddStep(&step.ListContainers{
ShowAll: true,
Format: `"{{.ID}}"`,
Filter: fmt.Sprintf("id=%s", containerId),
Out: &out,
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.Lambda{
Lambda: CheckContainerExist(host, role, containerId, &out),
})
t.AddStep(&step.ContainerExec{
ContainerId: &containerId,
Command: fmt.Sprintf(cmd, id),

Check failure on line 70 in internal/task/task/common/mark_chunkserver_pendding.go

View workflow job for this annotation

GitHub Actions / test

undefined: id
Success: &success,
Out: &out,
ExecOptions: curveadm.ExecOptions(),
})

return t, nil
}

0 comments on commit a389709

Please sign in to comment.