| 
 | 1 | +/*  | 
 | 2 | + *  Copyright (c) 2022 NetEase Inc.  | 
 | 3 | + *  | 
 | 4 | + *  Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + *  you may not use this file except in compliance with the License.  | 
 | 6 | + *  You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *      http://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + *  Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + *  distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + *  See the License for the specific language governing permissions and  | 
 | 14 | + *  limitations under the License.  | 
 | 15 | + */  | 
 | 16 | + | 
 | 17 | +/*  | 
 | 18 | + * Project: CurveAdm  | 
 | 19 | + * Created Date: 2023-11-30  | 
 | 20 | + * Author: Xianfei Cao (caoxianfei1)  | 
 | 21 | + */  | 
 | 22 | + | 
 | 23 | +package common  | 
 | 24 | + | 
 | 25 | +import (  | 
 | 26 | +	"fmt"  | 
 | 27 | + | 
 | 28 | +	"github.com/opencurve/curveadm/cli/cli"  | 
 | 29 | +	"github.com/opencurve/curveadm/internal/configure/topology"  | 
 | 30 | +	"github.com/opencurve/curveadm/internal/task/step"  | 
 | 31 | +	"github.com/opencurve/curveadm/internal/task/task"  | 
 | 32 | +	tui "github.com/opencurve/curveadm/internal/tui/common"  | 
 | 33 | +)  | 
 | 34 | + | 
 | 35 | +func NewMarkChunkserverPendding(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {  | 
 | 36 | +	serviceId := curveadm.GetServiceId(dc.GetId())  | 
 | 37 | +	containerId, err := curveadm.GetContainerId(serviceId)  | 
 | 38 | +	if curveadm.IsSkip(dc) {  | 
 | 39 | +		return nil, nil  | 
 | 40 | +	} else if err != nil {  | 
 | 41 | +		return nil, err  | 
 | 42 | +	}  | 
 | 43 | + | 
 | 44 | +	hc, err := curveadm.GetHost(dc.GetHost())  | 
 | 45 | +	if err != nil {  | 
 | 46 | +		return nil, err  | 
 | 47 | +	}  | 
 | 48 | + | 
 | 49 | +	// new task  | 
 | 50 | +	subname := fmt.Sprintf("host=%s role=%s containerId=%s",  | 
 | 51 | +		dc.GetHost(), dc.GetRole(), tui.TrimContainerId(containerId))  | 
 | 52 | +	t := task.NewTask("Mark chunkserver pendding", subname, hc.GetSSHConfig())  | 
 | 53 | + | 
 | 54 | +	var out string  | 
 | 55 | +	var success bool  | 
 | 56 | +	host, role := dc.GetHost(), dc.GetRole()  | 
 | 57 | +	cmd := "curvebs-tool -op=set_chunkserver -chunkserver_id=%s -chunkserver_status=pendding"  | 
 | 58 | +	t.AddStep(&step.ListContainers{  | 
 | 59 | +		ShowAll:     true,  | 
 | 60 | +		Format:      `"{{.ID}}"`,  | 
 | 61 | +		Filter:      fmt.Sprintf("id=%s", containerId),  | 
 | 62 | +		Out:         &out,  | 
 | 63 | +		ExecOptions: curveadm.ExecOptions(),  | 
 | 64 | +	})  | 
 | 65 | +	t.AddStep(&step.Lambda{  | 
 | 66 | +		Lambda: CheckContainerExist(host, role, containerId, &out),  | 
 | 67 | +	})  | 
 | 68 | +	t.AddStep(&step.ContainerExec{  | 
 | 69 | +		ContainerId: &containerId,  | 
 | 70 | +		Command:     fmt.Sprintf(cmd, id),  | 
 | 71 | +		Success:     &success,  | 
 | 72 | +		Out:         &out,  | 
 | 73 | +		ExecOptions: curveadm.ExecOptions(),  | 
 | 74 | +	})  | 
 | 75 | + | 
 | 76 | +	return t, nil  | 
 | 77 | +}  | 
0 commit comments