Ejemplo n.º 1
0
func (fe *FrontEnd) HandleToggleMode(c *gin.Context) {
	var params api.ToggleModeParams
	c.Bind(&params)

	var cmd cc.Command
	nodeId := params.NodeId

	if params.Action == "enable" && params.Perm == "read" {
		cmd = &command.EnableReadCommand{nodeId}
	} else if params.Action == "disable" && params.Perm == "read" {
		cmd = &command.DisableReadCommand{nodeId}
	} else if params.Action == "enable" && params.Perm == "write" {
		cmd = &command.EnableWriteCommand{nodeId}
	} else if params.Action == "disable" && params.Perm == "write" {
		cmd = &command.DisableWriteCommand{nodeId}
	} else {
		c.JSON(200, api.MakeFailureResponse("Invalid command"))
		return
	}

	result, err := fe.C.ProcessCommand(cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 2
0
func (fe *FrontEnd) HandleMigrateCreate(c *gin.Context) {
	var params api.MigrateParams
	c.Bind(&params)

	ranges := []topo.Range{}
	for _, r := range params.Ranges {
		xs := strings.Split(r, "-")
		if len(xs) == 2 {
			left, _ := strconv.Atoi(xs[0])
			right, _ := strconv.Atoi(xs[1])
			ranges = append(ranges, topo.Range{left, right})
		} else {
			left, _ := strconv.Atoi(r)
			ranges = append(ranges, topo.Range{left, left})
		}
	}

	cmd := command.MigrateCommand{
		SourceId: params.SourceId,
		TargetId: params.TargetId,
		Ranges:   ranges,
	}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 3
0
func (fe *FrontEnd) HandleLogSlice(c *gin.Context) {
	var params api.LogSliceParams
	c.Bind(&params)

	n := len(log.LogRingBuffer)
	lines := log.LogRingBuffer[n-params.Pos-params.Count : n-params.Pos]

	c.JSON(200, api.MakeSuccessResponse(lines))
}
Ejemplo n.º 4
0
func (fe *FrontEnd) HandleFixCluster(c *gin.Context) {
	cmd := command.FixClusterCommand{}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 5
0
func (fe *FrontEnd) HandleAppStatus(c *gin.Context) {
	cmd := command.AppStatusCommand{}

	result, err := cmd.Execute(fe.C)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 6
0
func (fe *FrontEnd) HandleMergeSeeds(c *gin.Context) {
	var params api.MergeSeedsParams
	c.Bind(&params)

	cmd := command.MergeSeedsCommand{params.Region, params.Seeds}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 7
0
func (fe *FrontEnd) HandleFailoverTakeover(c *gin.Context) {
	var params api.FailoverTakeoverParams
	c.Bind(&params)

	cmd := command.FailoverTakeoverCommand{params.NodeId}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 8
0
func (fe *FrontEnd) HandleReplicate(c *gin.Context) {
	var params api.ReplicateParams
	c.Bind(&params)

	cmd := command.ReplicateCommand{params.ChildId, params.ParentId}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 9
0
func (fe *FrontEnd) HandleMigrateCancel(c *gin.Context) {
	var params api.MigrateActionParams
	c.Bind(&params)

	cmd := command.MigrateCancelCommand{
		SourceId: params.SourceId,
	}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 10
0
func (fe *FrontEnd) HandleRegionSnapshot(c *gin.Context) {
	var params api.RegionSnapshotParams
	c.Bind(&params)

	cmd := command.UpdateRegionCommand{
		Region: params.Region,
		Nodes:  params.Nodes,
	}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 11
0
func (fe *FrontEnd) HandleRebalance(c *gin.Context) {
	var params api.RebalanceParams
	c.Bind(&params)

	cmd := command.RebalanceCommand{
		Method:       params.Method,
		Ratio:        params.Ratio,
		TargetIds:    params.TargetIds,
		ShowPlanOnly: params.ShowPlanOnly,
	}

	result, err := fe.C.ProcessCommand(&cmd, fe.ProcessTimeout*time.Second)
	if err != nil {
		c.JSON(200, api.MakeFailureResponse(err.Error()))
		return
	}

	c.JSON(200, api.MakeSuccessResponse(result))
}
Ejemplo n.º 12
0
func (fe *FrontEnd) HandleUpdateTokenId(c *gin.Context) {
	//do nothing,just return 200
	//this used to add token to memory
	c.JSON(200, api.MakeSuccessResponse(nil))
}