Пример #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))
}
Пример #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))
}
Пример #3
0
/* wrap a HandlerFunc to be authenticated */
func (t *TokenAuth) HandleFunc(handlerFunc gin.HandlerFunc) gin.HandlerFunc {
	return func(c *gin.Context) {
		req := c.Request
		_, err := t.Authenticate(req)
		if err != nil {
			c.JSON(200, api.MakeFailureResponse(err.Error()))
			return
		}
		handlerFunc(c)
	}
}
Пример #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))
}
Пример #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))
}
Пример #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))
}
Пример #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))
}
Пример #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))
}
Пример #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))
}
Пример #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))
}
Пример #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))
}