Esempio n. 1
0
func (h *HttpTransport) RemoteJobFor(locator transport.Locator, j interface{}) (job jobs.Job, err error) {
	baseUrl, errl := urlForLocator(locator)
	if errl != nil {
		err = errors.New("The provided host is not valid '" + locator.String() + "': " + errl.Error())
		return
	}
	httpJob, errh := HttpJobFor(j)
	if errh == jobs.ErrNoJobForRequest {
		err = transport.ErrNotTransportable
		return
	}
	if errh != nil {
		err = errh
		return
	}
	if serverAware, ok := httpJob.(ServerAware); ok {
		serverAware.SetServer(baseUrl.Host)
	}

	job = jobs.JobFunction(func(res jobs.Response) {
		if err := h.ExecuteRemote(baseUrl, httpJob, res); err != nil {
			res.Failure(err)
		}
	})
	return
}
Esempio n. 2
0
func (p SimplePlacement) RemoveFromLocation(on transport.Locator) bool {
	for _, l := range transport.Locators(p) {
		if l.String() == on.String() {
			return false
		}
	}
	return true
}
Esempio n. 3
0
func urlForLocator(locator transport.Locator) (*url.URL, error) {
	base := locator.String()
	if strings.Contains(base, ":") {
		host, port, err := net.SplitHostPort(base)
		if err != nil {
			return nil, err
		}
		if port == "" {
			base = net.JoinHostPort(host, DefaultHttpPort)
		}
	} else {
		base = net.JoinHostPort(base, DefaultHttpPort)
	}
	return &url.URL{Scheme: "http", Host: base}, nil
}
Esempio n. 4
0
func (t *testTransport) RemoteJobFor(locator transport.Locator, job jobs.Job) (jobs.Job, error) {
	if t.Translated == nil {
		t.Translated = make(map[string]jobs.Job)
		t.Invoked = make(map[string]jobs.Response)
	}
	t.Translated[locator.String()] = job
	invoked := func(res jobs.Response) {
		if _, found := t.Invoked[locator.String()]; found {
			panic(fmt.Sprintf("Same job %+v invoked twice under %s", job, locator.String()))
		}
		t.Invoked[locator.String()] = res
		res.Success(jobs.ResponseOk)
	}
	return jobs.JobFunction(invoked), nil
}
Esempio n. 5
0
func (h *HttpTransport) RemoteJobFor(locator transport.Locator, j jobs.Job) (job jobs.Job, err error) {
	if locator == transport.Local {
		job = j
		return
	}
	baseUrl, errl := urlForLocator(locator)
	if errl != nil {
		err = errors.New("The provided host is not valid '" + locator.String() + "': " + errl.Error())
		return
	}
	httpJob, errh := HttpJobFor(j)
	if errh != nil {
		err = errh
		return
	}

	job = jobs.JobFunction(func(res jobs.Response) {
		if err := h.ExecuteRemote(baseUrl, httpJob, res); err != nil {
			res.Failure(err)
		}
	})
	return
}
Esempio n. 6
0
func (i *Instance) Place(on transport.Locator) {
	i.on = on
	s := on.String()
	i.On = &s
}