예제 #1
0
func Data(request *cheshire.Request, conn cheshire.Connection) {
	part, ok := request.Params().GetInt("partition")
	if !ok {
		conn.Write(request.NewError(406, fmt.Sprintf("partition param is manditory")))
		return
	}

	remove := request.Params().MustBool("remove", false)
	dataChan := make(chan *dynmap.DynMap, 10)
	finishedChan := make(chan int)
	errorChan := make(chan error)
	go func() {
		for {
			select {
			case data := <-dataChan:
				//send a data packet
				res := request.NewResponse()
				res.SetTxnStatus("continue")
				res.Put("data", data)
				conn.Write(res)
			case <-finishedChan:
				res := request.NewResponse()
				res.SetTxnStatus("complete")
				conn.Write(res)
				return
			case err := <-errorChan:
				conn.Write(request.NewError(406, fmt.Sprintf("Unable to unlock (%s)", err)))
				return
			}
		}
	}()
	partitioner.Data(part, remove, dataChan, finishedChan, errorChan)
}
예제 #2
0
func Unlock(request *cheshire.Request, conn cheshire.Connection) {
	partitions, ok := request.Params().GetIntSliceSplit("partitions", ",")
	if !ok {
		conn.Write(request.NewError(406, fmt.Sprintf("partitions param missing")))
		return
	}
	err := partitioner.Unlock(partitions)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unable to unlock (%s)", err)))
		return
	}
	conn.Write(request.NewResponse())
}
예제 #3
0
func SetRouterTable(request *cheshire.Request, conn cheshire.Connection) {
	rtmap, ok := request.Params().GetDynMap("router_table")
	if !ok {
		conn.Write(request.NewError(406, "No router_table"))
		return
	}

	rt, err := ToRouterTable(rtmap)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unparsable router table (%s)", err)))
		return
	}

	err = partitioner.SetRouterTable(rt)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unable to set router table (%s)", err)))
		return
	}
	conn.Write(request.NewResponse())
}