Beispiel #1
0
func (ec *elasticConnection) Delete(key datastore.Key) error {
	//func Delete(pretty bool, index string, _type string, id string, version int, routing string) (api.BaseResponse, error) {
	resp, err := core.Delete(false, ec.index, key.Kind(), key.ID(), 0, "")
	indices.Refresh(ec.index)
	glog.V(4).Infof("Delete response: %v", resp)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
// delete common code for removing an entity and publishes events
func (f *Facade) delete(ctx datastore.Context, ds datastore.EntityStore, key datastore.Key, be beforeEvent, ae afterEvent) error {
	glog.V(2).Infof("Facade.delete: %s:%s", key.Kind(), key.ID())
	ec := newEventCtx()
	err := f.beforeEvent(be, ec, key.ID())
	if err == nil {
		err = ds.Delete(ctx, key)
	}
	defer f.afterEvent(ae, ec, key.ID(), err)
	return err
}
Beispiel #3
0
func (ec *elasticConnection) Put(key datastore.Key, msg datastore.JSONMessage) error {
	//func Index(pretty bool, index string, _type string, id string, data interface{}) (api.BaseResponse, error) {

	glog.V(4).Infof("Put for {kind:%s, id:%s} %v", key.Kind(), key.ID(), string(msg.Bytes()))
	var raw json.RawMessage
	raw = msg.Bytes()
	resp, err := core.IndexWithParameters(false, ec.index, key.Kind(), key.ID(), "", msg.Version(), "", "", "", 0, "", "", false, &raw)
	if err != nil {
		glog.Errorf("Put err: %+v", err)
		if eserr, iseserror := err.(api.ESError); iseserror && eserr.Code == 409 {
			// Conflict
			return fmt.Errorf("Your changes conflict with those made by another user. Please reload and try your changes again.")
		}
		return err
	}
	indices.Refresh(ec.index)
	glog.V(4).Infof("Put response: %v", resp)
	if !resp.Ok {
		return fmt.Errorf("non OK response: %v", resp)
	}
	return nil
}
Beispiel #4
0
func (ec *elasticConnection) Get(key datastore.Key) (datastore.JSONMessage, error) {
	//	func Get(pretty bool, index string, _type string, id string) (api.BaseResponse, error) {
	glog.V(4).Infof("Get for {kind:%v, id:%v}", key.Kind(), key.ID())
	//	err := core.GetSource(ec.index, key.Kind(), key.ID(), &bytes)
	response, err := elasticGet(false, ec.index, key.Kind(), key.ID())
	if err != nil {
		glog.Errorf("Error is %v", err)
		return nil, err
	}
	if !response.Exists {
		glog.V(4).Infof("Entity not found for {kind:%s, id:%s}", key.Kind(), key.ID())
		return nil, datastore.ErrNoSuchEntity{Key: key}
	}
	bytes := response.Source
	msg := datastore.NewJSONMessage(bytes, response.Version)
	return msg, nil
}