Ejemplo n.º 1
0
//verify makes sure that the arguments are all specified correctly and returns
//an error that can be encoded over an rpc request.
func verify(args *rpc.AnnounceArgs) (err error) {
	switch {
	case args.GOARCH == "":
		err = rpc.Errorf("GOARCH unspecified")
	case args.GOOS == "":
		err = rpc.Errorf("GOOS unspecified")
	case !isEntity(args.Type):
		err = rpc.Errorf("unknown Type: %s", args.Type)
	case args.URL == "":
		err = rpc.Errorf("URL unspecified")
	}
	return
}
Ejemplo n.º 2
0
//Request grabs the data for the test so the test runner can request the data
//it needs to run.
func (r *Runner) Request(req *http.Request, args *rpc.TestRequest, resp *rpc.RunTest) (err error) {
	//make sure its for the id we're managing
	if args.ID != r.task.ID {
		err = rpc.Errorf("unknown ID: %s", args.ID)
		return
	}

	//ensure the index is ok
	if args.Index < 0 || len(r.task.Tests) <= args.Index {
		err = rpc.Errorf("invalid index: %d not in [0, %d)", args.Index, len(r.task.Tests))
		return
	}

	//set the response
	*resp = r.task.Tests[args.Index]
	return
}
Ejemplo n.º 3
0
//Request grabs the data for the test so the test runner can request the data
//it needs to run.
func (r *Runner) Request(req *http.Request, args *rpc.TestRequest, resp *rpc.RunTest) (err error) {
	//grab the task managing this request
	task, ok := r.tm.Lookup(args.ID)
	if !ok {
		err = rpc.Errorf("unknown ID: %s", args.ID)
		return
	}

	//ensure the index is ok
	if args.Index < 0 || len(task.task.Tests) <= args.Index {
		err = rpc.Errorf("invalid index: %d not in [0, %d)", args.Index, len(task.task.Tests))
		return
	}

	//set the response
	*resp = task.task.Tests[args.Index]
	return
}
Ejemplo n.º 4
0
//Post grabs the test output and sends it to the corresponding task managing it.
func (r *Runner) Post(req *http.Request, args *rpc.TestResponse, resp *rpc.None) (err error) {
	//make sure its for the id we're managing
	if args.ID != r.task.ID {
		err = rpc.Errorf("unknown ID: %s", args.ID)
		return
	}

	//send it the output
	r.resp <- args.Output
	return
}
Ejemplo n.º 5
0
//Post grabs the test output and sends it to the corresponding task managing
//it.
func (r *Runner) Post(req *http.Request, args *rpc.TestResponse, resp *rpc.None) (err error) {
	//grab the task managing this output
	task, ok := r.tm.Lookup(args.ID)
	if !ok {
		err = rpc.Errorf("unknown ID: %s", args.ID)
		return
	}

	//send it the output
	task.resps <- args.Output
	return
}
Ejemplo n.º 6
0
//Remove removes a service from the tracker.
func (Tracker) Remove(req *http.Request, args *rpc.RemoveArgs, rep *rpc.None) (err error) {
	//wrap our error on the way out
	defer rpc.Wrap(&err)

	//create our context
	ctx := httputil.NewContext(req)
	defer ctx.Close()
	ctx.Infof("Got a remove request from %s: %+v", req.RemoteAddr, args)

	//get the key from the argument
	key := bson.ObjectIdHex(args.Key)

	//make sure its an entity
	if !isEntity(args.Kind) {
		err = rpc.Errorf("kind is not Builder or Runner")
		return
	}

	//remove it from the database
	err = ctx.DB.C(args.Kind).Remove(bson.M{"_id": key})
	return
}