Ejemplo n.º 1
0
// protoToRecord converts a RequestLog, the internal Protocol Buffer
// representation of a single request-level log, to a Record, its
// corresponding external representation.
func protoToRecord(rl *log_proto.RequestLog) *Record {
	return &Record{
		AppID:             *rl.AppId,
		VersionID:         *rl.VersionId,
		RequestID:         *rl.RequestId,
		IP:                *rl.Ip,
		Nickname:          proto.GetString(rl.Nickname),
		StartTime:         *rl.StartTime,
		EndTime:           *rl.EndTime,
		Latency:           *rl.Latency,
		MCycles:           *rl.Mcycles,
		Method:            *rl.Method,
		Resource:          *rl.Resource,
		HTTPVersion:       *rl.HttpVersion,
		Status:            *rl.Status,
		ResponseSize:      *rl.ResponseSize,
		Referrer:          proto.GetString(rl.Referrer),
		UserAgent:         proto.GetString(rl.UserAgent),
		URLMapEntry:       *rl.UrlMapEntry,
		Combined:          *rl.Combined,
		APIMCycles:        proto.GetInt64(rl.ApiMcycles),
		Host:              proto.GetString(rl.Host),
		Cost:              proto.GetFloat64(rl.Cost),
		TaskQueueName:     proto.GetString(rl.TaskQueueName),
		TaskName:          proto.GetString(rl.TaskName),
		WasLoadingRequest: proto.GetBool(rl.WasLoadingRequest),
		PendingTime:       proto.GetInt64(rl.PendingTime),
		Finished:          proto.GetBool(rl.Finished),
		AppLogs:           protoToAppLogs(rl.Line),
	}
}
Ejemplo n.º 2
0
func (*MyCalcService) Divide(req *CalcRequest, resp *CalcResponse) (err os.Error) {
	resp.Result = proto.Int64(0)
	defer func() {
		if x := recover(); x != nil {
			if ex, ok := x.(os.Error); ok {
				err = ex
			} else {
				err = os.ErrorString(fmt.Sprint(x))
			}
		}
	}()
	resp.Result = proto.Int64(proto.GetInt64(req.A) / proto.GetInt64(req.B))
	resp.Remainder = proto.Int64(proto.GetInt64(req.A) % proto.GetInt64(req.B))
	return
}
Ejemplo n.º 3
0
Archivo: client.go Proyecto: kr/doozer
func (c *conn) events(t *T) (*Watch, os.Error) {
	cb, err := c.send(t)
	if err != nil {
		return nil, err
	}

	evs := make(chan *Event)
	w := &Watch{evs, c, cb, *t.Tag}
	go func() {
		for r := range cb {
			var ev Event
			if err := r.err(); err != nil {
				ev.Err = err
			} else {
				ev.Rev = pb.GetInt64(r.Rev)
				ev.Path = pb.GetString(r.Path)
				ev.Body = r.Value
				ev.Flag = pb.GetInt32(r.Flags)
			}
			evs <- &ev
		}
		close(evs)
	}()

	return w, nil
}
Ejemplo n.º 4
0
Archivo: server.go Proyecto: kr/doozerd
func (c *conn) watch(t *T, tx txn) {
	pat := pb.GetString(t.Path)
	glob, err := store.CompileGlob(pat)
	if err != nil {
		c.respond(t, Valid|Done, nil, errResponse(err))
		return
	}

	var w *store.Watch
	rev := pb.GetInt64(t.Rev)
	if rev == 0 {
		w, err = store.NewWatch(c.s.St, glob), nil
	} else {
		w, err = store.NewWatchFrom(c.s.St, glob, rev)
	}

	switch err {
	case nil:
		// nothing
	case store.ErrTooLate:
		c.respond(t, Valid|Done, nil, tooLate)
	default:
		c.respond(t, Valid|Done, nil, errResponse(err))
	}

	go func() {
		defer w.Stop()

		// TODO buffer (and possibly discard) events
		for {
			select {
			case ev := <-w.C:
				if closed(w.C) {
					return
				}

				r := R{
					Path:  &ev.Path,
					Value: []byte(ev.Body),
					Rev:   &ev.Seqn,
				}

				var flag int32
				switch {
				case ev.IsSet():
					flag = Set
				case ev.IsDel():
					flag = Del
				}

				c.respond(t, Valid|flag, tx.cancel, &r)

			case <-tx.cancel:
				c.closeTxn(*t.Tag)
				return
			}
		}
	}()
}
Ejemplo n.º 5
0
Archivo: client.go Proyecto: kr/doozer
func (cl *Client) Set(path string, oldRev int64, body []byte) (newRev int64, err os.Error) {
	r, err := cl.call(&T{Verb: set, Path: &path, Value: body, Rev: &oldRev})
	if err != nil {
		return 0, err
	}

	return pb.GetInt64(r.Rev), nil
}
Ejemplo n.º 6
0
Archivo: client.go Proyecto: kr/doozer
// Returns the body and revision of the file at path.
// If rev is 0, uses the current state, otherwise,
// rev must be a value previously returned buy an operation.
// If path does not denote a file, returns an error.
func (cl *Client) Get(path string, rev *int64) ([]byte, int64, os.Error) {
	r, err := cl.retry(&T{Verb: get, Path: &path, Rev: rev})
	if err != nil {
		return nil, 0, err
	}

	return r.Value, pb.GetInt64(r.Rev), nil
}
Ejemplo n.º 7
0
Archivo: client.go Proyecto: kr/doozer
func (cl *Client) Stat(path string, rev *int64) (int32, int64, os.Error) {
	r, err := cl.retry(&T{Verb: stat, Path: &path, Rev: rev})
	if err != nil {
		return 0, 0, err
	}

	return pb.GetInt32(r.Len), pb.GetInt64(r.Rev), nil
}
Ejemplo n.º 8
0
Archivo: client.go Proyecto: kr/doozer
func (c *conn) readResponses() {
	defer c.close()

	for {
		r, err := c.readR()
		if err != nil {
			c.clk.Lock()
			if c.err == nil {
				c.err = err
			}
			c.clk.Unlock()
			return
		}

		if r.ErrCode != nil && *r.ErrCode == proto.Response_REDIRECT {
			c.redirectAddr = pb.GetString(r.ErrDetail)
			c.redirected = true
		}

		tag := pb.GetInt32(r.Tag)
		flags := pb.GetInt32(r.Flags)

		c.cblk.Lock()
		ch, ok := c.cb[tag]
		if ok && ch == nil {
			c.cblk.Unlock()
			continue
		}
		if flags&Done != 0 {
			c.cb[tag] = nil, false
		}
		c.cblk.Unlock()

		if !ok {
			log.Printf(
				"%v unexpected: tag=%d flags=%d rev=%d path=%q value=%v len=%d err_code=%v err_detail=%q",
				ch,
				tag,
				flags,
				pb.GetInt64(r.Rev),
				pb.GetString(r.Path),
				r.Value,
				pb.GetInt32(r.Len),
				pb.GetInt32((*int32)(r.ErrCode)),
				pb.GetString(r.ErrDetail),
			)
			continue
		}

		if flags&Valid != 0 {
			ch <- r
		}

		if flags&Done != 0 {
			close(ch)
		}
	}
}
Ejemplo n.º 9
0
Archivo: nagios.go Proyecto: pjjw/ncd
func (c *CheckResult) stringMap() (smap map[string]string) {
	smap = map[string]string{
		"Hostname":    fmt.Sprintf("%s", proto.GetString(c.Hostname)),
		"ServiceName": fmt.Sprintf("%s", proto.GetString(c.ServiceName)),
		"Status":      fmt.Sprintf("%d", int32((*c.Status))),
		"CheckPassive": fmt.Sprintf("%d", func() (i int32) {
			if proto.GetBool(c.CheckPassive) {
				i = 1
			} else {
				i = 0
			}
			return i
		}()),
		"CheckOutput":    fmt.Sprintf("%s", strings.Trim(strconv.Quote(proto.GetString(c.CheckOutput)), "\"")),
		"StartTimestamp": fmt.Sprintf("%f", float64(proto.GetInt64(c.StartTimestamp))/1000000000),
		"EndTimestamp":   fmt.Sprintf("%f", float64(proto.GetInt64(c.EndTimestamp))/1000000000),
		"TimeNow":        fmt.Sprintf("%d", time.Seconds()),
	}
	return smap
}
Ejemplo n.º 10
0
// Stat returns metadata about the file or directory at path,
// in revision *storeRev. If storeRev is nil, uses the current
// revision.
func (c *Conn) Stat(path string, storeRev *int64) (len int, fileRev int64, err os.Error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_STAT)
	t.req.Path = &path
	t.req.Rev = storeRev

	err = c.call(&t)
	if err != nil {
		return 0, 0, err
	}

	return int(proto.GetInt32(t.resp.Len)), proto.GetInt64(t.resp.Rev), nil
}
Ejemplo n.º 11
0
// Returns the body and revision of the file at path,
// as of store revision *rev.
// If rev is nil, uses the current state.
func (c *Conn) Get(file string, rev *int64) ([]byte, int64, os.Error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_GET)
	t.req.Path = &file
	t.req.Rev = rev

	err := c.call(&t)
	if err != nil {
		return nil, 0, err
	}

	return t.resp.Value, proto.GetInt64(t.resp.Rev), nil
}
Ejemplo n.º 12
0
// Sets the contents of file to body, if it hasn't been modified since oldRev.
func (c *Conn) Set(file string, oldRev int64, body []byte) (newRev int64, err os.Error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_SET)
	t.req.Path = &file
	t.req.Value = body
	t.req.Rev = &oldRev

	err = c.call(&t)
	if err != nil {
		return
	}

	return proto.GetInt64(t.resp.Rev), nil
}
Ejemplo n.º 13
0
// referenceValueToKey is the same as protoToKey except the input is a
// PropertyValue_ReferenceValue instead of a Reference.
func referenceValueToKey(r *pb.PropertyValue_ReferenceValue) (k *Key, err error) {
	appID := proto.GetString(r.App)
	for _, e := range r.Pathelement {
		k = &Key{
			kind:     proto.GetString(e.Type),
			stringID: proto.GetString(e.Name),
			intID:    proto.GetInt64(e.Id),
			parent:   k,
			appID:    appID,
		}
		if !k.valid() {
			return nil, ErrInvalidKey
		}
	}
	return
}
Ejemplo n.º 14
0
func (c *conn) wait(t *T, tx txn) {
	pat := pb.GetString(t.Path)
	glob, err := store.CompileGlob(pat)
	if err != nil {
		c.respond(t, Valid|Done, nil, errResponse(err))
		return
	}

	var w *store.Watch
	rev := pb.GetInt64(t.Rev)
	if rev == 0 {
		w, err = store.NewWatch(c.s.St, glob), nil
	} else {
		w, err = store.NewWatchFrom(c.s.St, glob, rev)
	}

	switch err {
	case nil:
		// nothing
	case store.ErrTooLate:
		c.respond(t, Valid|Done, nil, tooLate)
	default:
		c.respond(t, Valid|Done, nil, errResponse(err))
	}

	go func() {
		defer w.Stop()
		ev := <-w.C
		r := R{
			Path:  &ev.Path,
			Value: []byte(ev.Body),
			Rev:   &ev.Seqn,
		}

		var flag int32
		switch {
		case ev.IsSet():
			flag = Set
		case ev.IsDel():
			flag = Del
		}

		c.respond(t, Valid|flag, nil, &r)
	}()
}
Ejemplo n.º 15
0
func doCalc(calc CalcService) {
	crq := new(CalcRequest)
	crs := new(CalcResponse)

	// add
	crq.A = proto.Int64(61)
	crq.B = proto.Int64(35)

	err := calc.Add(crq, crs)
	if err != nil {
		log.Println("add error:", err)
	}

	log.Println("add result:", proto.GetInt64(crs.Result))

	crq.Reset()
	crs.Reset()

	// subtract
	crq.A = proto.Int64(61)
	crq.B = proto.Int64(35)

	err = calc.Subtract(crq, crs)
	if err != nil {
		log.Println("subtract error:", err)
	}

	log.Println("subtract result:", proto.GetInt64(crs.Result))

	crq.Reset()
	crs.Reset()

	// multiply
	crq.A = proto.Int64(9)
	crq.B = proto.Int64(11)

	err = calc.Multiply(crq, crs)
	if err != nil {
		log.Println("multiply error:", err)
	}

	log.Println("multiply result:", proto.GetInt64(crs.Result))

	crq.Reset()
	crs.Reset()

	// divide
	crq.A = proto.Int64(20)
	crq.B = proto.Int64(8)

	err = calc.Divide(crq, crs)
	if err != nil {
		log.Println("divide error:", err)
	}

	log.Println("divide result:", proto.GetInt64(crs.Result))
	log.Println("divide remainder:", proto.GetInt64(crs.Remainder))

	crq.Reset()
	crs.Reset()

}
Ejemplo n.º 16
0
func (*MyCalcService) Subtract(req *CalcRequest, resp *CalcResponse) os.Error {
	resp.Result = proto.Int64(proto.GetInt64(req.A) - proto.GetInt64(req.B))
	return nil
}
Ejemplo n.º 17
0
func (*MyCalcService) Multiply(req *CalcRequest, resp *CalcResponse) os.Error {
	resp.Result = proto.Int64(proto.GetInt64(req.A) * proto.GetInt64(req.B))
	return nil
}