Exemple #1
0
func processGetChildrenReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*GetChildrenReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	children, err := client.GetChildren(req.Path.Value)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&GetChildrenRep{Children: children},
	)
}
Exemple #2
0
func processSetDataReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*SetDataReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	err := client.SetData(req.Path.Value, string(req.Data), req.Version)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&SetDataRep{Stat: newStat(0, 0, 0)},
	)
}
Exemple #3
0
func processExistsReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*ExistsReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	err := client.Exists(req.Path.Value)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&ExistsRep{Stat: newStat(0, 0, 0)},
	)
}
Exemple #4
0
func processDeleteReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*DeleteReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	err := client.Delete(req.Path.Value, req.Version)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&DeleteRep{},
	)
}
Exemple #5
0
func processCreateReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*CreateReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	err := client.Create(req.Path.Value, string(req.Data))
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&CreateRep{Path: req.Path.Value},
	)
}
Exemple #6
0
func processGetDataReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*GetDataReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	node, err := client.GetData(req.Path.Value)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	return newRep(
		xid, 0, errOk,
		&GetDataRep{
			Data: []byte(node.Value),
			Stat: newStat(node.CreatedIndex, node.ModifiedIndex, len(node.Value)),
		},
	)
}
Exemple #7
0
func processCheckVersionReq(opReq OpReq, client kv.Client) *OpRep {
	xid := opReq.Hdr.Xid
	req := opReq.Req.(*CheckVersionReq)
	if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil {
		return err
	}

	node, err := client.GetData(req.Path.Value)
	if err != nil {
		return newBackendErrorRep(xid, 0, err)
	}

	if req.Version != int32(node.ModifiedIndex) {
		return newErrorRep(xid, 0, errBadVersion)
	}

	return newRep(
		xid, 0, errOk,
		&PingRep{},
	)
}